@ysgroup/ui 0.1.45 → 0.1.47

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,17 +1,18 @@
1
1
  {
2
2
  "name": "@ysgroup/ui",
3
- "version": "0.1.45",
3
+ "version": "0.1.47",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
7
7
  "dependencies": {
8
8
  "@e965/xlsx": "0.20.3",
9
9
  "@element-plus/icons-vue": "^2.3.1",
10
- "@ysgroup/contracts": "0.1.8",
11
10
  "pdfjs-dist": "6.5.438"
12
11
  },
13
12
  "peerDependencies": {
14
- "@ysgroup/theme": ">=0.3.0",
13
+ "@ysgroup/contracts": ">=0.1.50",
14
+ "@ysgroup/core": ">=0.1.28",
15
+ "@ysgroup/theme": ">=0.3.1",
15
16
  "element-plus": ">=2.9",
16
17
  "vue": ">=3.5"
17
18
  },
@@ -24,7 +25,9 @@
24
25
  "access": "public"
25
26
  },
26
27
  "devDependencies": {
27
- "docx-preview": "^0.4.1",
28
- "@ysgroup/theme": "^0.3.0"
28
+ "@ysgroup/contracts": "^0.1.50",
29
+ "@ysgroup/core": "^0.1.28",
30
+ "@ysgroup/theme": "^0.3.1",
31
+ "docx-preview": "^0.4.1"
29
32
  }
30
33
  }
@@ -0,0 +1,68 @@
1
+ <!-- YsAmount —— 表格里的金额单元格(规范 8.5「数值列」):按大小自动换单位,列名只写「金额」「市值」,不写单位。
2
+ 不足 1 万显示原数(1,377.00),满 1 万「123.48万」,满 1 亿「3.56亿」;换算过的值鼠标移上立即显示完整金额(1,234,756.78)。
3
+ 所在列 align="right"。盈亏、涨跌加 signed(正数带 +)和 updown(涨红跌绿,跟随 --ys-color-up / -down)。
4
+ 搜索文本传 formatAmount(值) 和原值,显示的「123.48万」和原值都能搜到。
5
+
6
+ <el-table-column label="金额" :width="columnWidth('orders', 'amount')" align="right">
7
+ <template #default="{ row }"><YsAmount :value="row.amount" /></template>
8
+ </el-table-column> -->
9
+ <script setup lang="ts">
10
+ import { computed } from "vue";
11
+ import { splitAmount } from "@ysgroup/core";
12
+ import { vTip } from "../vTip";
13
+
14
+ const props = withDefaults(
15
+ defineProps<{
16
+ value: number | string | null | undefined;
17
+ /** 小数位,默认 2。 */
18
+ digits?: number;
19
+ /** 正数带「+」(盈亏、涨跌)。 */
20
+ signed?: boolean;
21
+ /** 涨红跌绿,0 不上色。 */
22
+ updown?: boolean;
23
+ /** 空值显示,默认「—」。 */
24
+ empty?: string;
25
+ }>(),
26
+ { digits: 2, signed: false, updown: false, empty: "—" },
27
+ );
28
+
29
+ const parts = computed(() => splitAmount(props.value, { digits: props.digits, signed: props.signed }));
30
+ const tone = computed(() => {
31
+ if (!props.updown || !parts.value?.sign) return "";
32
+ return parts.value.sign > 0 ? "is-up" : "is-down";
33
+ });
34
+ </script>
35
+
36
+ <template>
37
+ <span v-if="parts" v-tip="parts.unit ? parts.full : ''" class="ys-amount" :class="[tone, { 'has-unit': parts.unit }]"
38
+ >{{ parts.number }}<span v-if="parts.unit" class="ys-amount__unit">{{ parts.unit }}</span></span
39
+ >
40
+ <span v-else class="ys-amount is-empty">{{ empty }}</span>
41
+ </template>
42
+
43
+ <style scoped>
44
+ .ys-amount {
45
+ font-variant-numeric: tabular-nums;
46
+ white-space: nowrap;
47
+ }
48
+ /* 单位比数字退后一档:颜色淡一级、字号略小,数字仍是视觉重心 */
49
+ .ys-amount__unit {
50
+ margin-left: 1px;
51
+ color: var(--ys-color-text-3);
52
+ font-size: 0.92em;
53
+ }
54
+ .ys-amount.has-unit {
55
+ cursor: default;
56
+ }
57
+ .ys-amount.is-up,
58
+ .ys-amount.is-up .ys-amount__unit {
59
+ color: var(--ys-color-up);
60
+ }
61
+ .ys-amount.is-down,
62
+ .ys-amount.is-down .ys-amount__unit {
63
+ color: var(--ys-color-down);
64
+ }
65
+ .ys-amount.is-empty {
66
+ color: var(--ys-color-text-3);
67
+ }
68
+ </style>
@@ -147,11 +147,15 @@ function settingsCommand(command: string) {
147
147
  background: var(--ys-color-bg-hover);
148
148
  color: var(--ys-color-primary);
149
149
  }
150
- /* 顶栏图标按钮不画聚焦框:菜单关闭后焦点会回到按钮,框时有时无反而像出错。 */
151
- .ys-app-toolbar__button:focus,
152
- .ys-app-toolbar__button:focus-visible {
150
+ /* 顶栏图标按钮只在键盘操作时画聚焦框(:focus-visible):鼠标点开菜单再关闭,焦点回到按钮也不画,不会时有时无。 */
151
+ .ys-app-toolbar__button:focus {
153
152
  outline: none;
154
153
  }
154
+ .ys-app-toolbar__button:focus-visible {
155
+ outline: var(--ys-focus-outline);
156
+ outline-offset: -2px;
157
+ color: var(--ys-color-primary);
158
+ }
155
159
  @media (max-width: 600px) {
156
160
  .ys-app-toolbar {
157
161
  padding-left: 4px;
@@ -21,8 +21,9 @@ defineProps<{
21
21
  .ys-bool-mark {
22
22
  vertical-align: middle;
23
23
  }
24
+ /* 图形用的成功色:比文字成功色亮一档,一眼看得出「是」 */
24
25
  .ys-bool-mark.is-yes {
25
- color: var(--ys-color-success);
26
+ color: var(--ys-color-success-mark);
26
27
  }
27
28
  .ys-bool-mark.is-no {
28
29
  color: color-mix(in srgb, var(--ys-color-text-3) 35%, var(--ys-color-bg-elevated));
@@ -4,6 +4,7 @@
4
4
  <script setup lang="ts">
5
5
  import { computed, ref, watch } from "vue";
6
6
  import { FIELD_SPECS, ENUM_META } from "@ysgroup/contracts";
7
+ import { ysMatch, ysSearchText } from "@ysgroup/core";
7
8
  import { enumLabel } from "../tokens-runtime";
8
9
  import { columnWidth as lookupColumnWidth } from "../columnWidths";
9
10
  import YsBoolMark from "./YsBoolMark.vue";
@@ -63,10 +64,21 @@ const displayColumns = computed<FieldSpec[]>(() => {
63
64
  return allSpecs.value.filter((f) => f.sensitivity === "public").slice(0, 6);
64
65
  });
65
66
 
67
+ // 每行的搜索文本(显示的文字 + 数字原值)只在行或列变化时拼一次;中文、拼音首字母、全拼、带不带千分位的数字都能搜。
68
+ const searchTexts = computed(() =>
69
+ props.rows.map((r) =>
70
+ ysSearchText(
71
+ displayColumns.value.map((c) => {
72
+ const raw = r[c.key];
73
+ return typeof raw === "number" ? [display(r, c), raw] : display(r, c);
74
+ }),
75
+ ),
76
+ ),
77
+ );
66
78
  const filtered = computed(() => {
67
- const kw = keyword.value.trim().toLowerCase();
68
- if (!kw) return props.rows;
69
- return props.rows.filter((r) => displayColumns.value.some((c) => display(r, c).toLowerCase().includes(kw)));
79
+ if (!keyword.value.trim()) return props.rows;
80
+ const texts = searchTexts.value;
81
+ return props.rows.filter((_, index) => ysMatch(texts[index], keyword.value));
70
82
  });
71
83
 
72
84
  // 搜索词变化时重置到第一页
@@ -0,0 +1,138 @@
1
+ <!-- YsDialog —— 统一弹窗外壳:点遮罩不关闭;底部「取消 / 确认」;dirty 时关闭前先确认;提交中不能关闭。
2
+ 用法:
3
+ <YsDialog v-model="open" :title="dialogTitle('编辑', row.code, row.name)" :dirty="dirty" :confirm-loading="saving" @confirm="save">
4
+ <el-form>…</el-form>
5
+ </YsDialog>
6
+ save 成功后由调用方把 v-model 设为 false(这样关闭不经过 dirty 确认,也不触发 cancel)。
7
+ 其余属性(top、fullscreen、draggable、class……)透传给 el-dialog。 -->
8
+ <script setup lang="ts">
9
+ import { computed, useAttrs } from "vue";
10
+ import { ysConfirm } from "../dialog";
11
+
12
+ defineOptions({ inheritAttrs: false });
13
+
14
+ const props = withDefaults(
15
+ defineProps<{
16
+ modelValue: boolean;
17
+ title?: string;
18
+ width?: string | number;
19
+ /** 有未保存的修改:点右上角关闭、按 Esc、点取消都先问「放弃未保存的修改?」。 */
20
+ dirty?: boolean;
21
+ /** 提交中:确认按钮转圈,取消、右上角关闭、Esc 都不起作用。 */
22
+ confirmLoading?: boolean;
23
+ confirmText?: string;
24
+ cancelText?: string;
25
+ confirmDisabled?: boolean;
26
+ /** 确认按钮颜色,危险操作传 danger。 */
27
+ confirmType?: "primary" | "danger" | "warning" | "success";
28
+ /** 不要底部按钮区。 */
29
+ hideFooter?: boolean;
30
+ appendToBody?: boolean;
31
+ destroyOnClose?: boolean;
32
+ }>(),
33
+ {
34
+ title: "",
35
+ width: "520px",
36
+ dirty: false,
37
+ confirmLoading: false,
38
+ confirmText: "保存",
39
+ cancelText: "取消",
40
+ confirmDisabled: false,
41
+ confirmType: "primary",
42
+ hideFooter: false,
43
+ appendToBody: false,
44
+ destroyOnClose: false,
45
+ },
46
+ );
47
+
48
+ const emit = defineEmits<{
49
+ "update:modelValue": [value: boolean];
50
+ /** 点了确认按钮。弹窗不会自己关,保存成功后由调用方关。 */
51
+ confirm: [];
52
+ /** 用户放弃:点取消、右上角关闭或按 Esc(dirty 时已确认放弃)。调用方把 v-model 设为 false 不触发。 */
53
+ cancel: [];
54
+ /** 关闭动画结束。 */
55
+ closed: [];
56
+ }>();
57
+
58
+ /** 这几项固定,不接受透传覆盖。 */
59
+ const FIXED = new Set(["closeOnClickModal", "close-on-click-modal", "beforeClose", "before-close"]);
60
+ const attrs = useAttrs();
61
+ const passAttrs = computed(() => Object.fromEntries(Object.entries(attrs).filter(([key]) => !FIXED.has(key))));
62
+
63
+ let asking = false;
64
+ /** 提交中不允许关闭:否则不知道有没有保存,重新打开还可能重复提交。 */
65
+ async function allowClose(): Promise<boolean> {
66
+ if (props.confirmLoading || asking) return false;
67
+ if (!props.dirty) return true;
68
+ asking = true;
69
+ try {
70
+ return await ysConfirm("放弃未保存的修改?", { title: "关闭确认", confirmText: "放弃修改", cancelText: "继续编辑" });
71
+ } finally {
72
+ asking = false;
73
+ }
74
+ }
75
+
76
+ /** 点取消、右上角关闭、Esc 都走这里:先发 cancel,再把 v-model 置为 false,由调用方的 v-model 关闭弹窗。 */
77
+ async function cancel() {
78
+ if (!(await allowClose())) return;
79
+ emit("cancel");
80
+ emit("update:modelValue", false);
81
+ }
82
+
83
+ /** el-dialog 关闭后还会再报一次 false,已经同步过的不重复发。 */
84
+ function onInnerUpdate(value: boolean) {
85
+ if (value !== props.modelValue) emit("update:modelValue", value);
86
+ }
87
+ </script>
88
+
89
+ <template>
90
+ <el-dialog
91
+ v-bind="passAttrs"
92
+ class="ys-dialog"
93
+ :model-value="modelValue"
94
+ :title="title"
95
+ :width="width"
96
+ :append-to-body="appendToBody"
97
+ :destroy-on-close="destroyOnClose"
98
+ :show-close="!confirmLoading"
99
+ :close-on-click-modal="false"
100
+ :before-close="cancel"
101
+ @update:model-value="onInnerUpdate"
102
+ @closed="emit('closed')"
103
+ >
104
+ <slot />
105
+ <template v-if="!hideFooter" #footer>
106
+ <slot name="footer">
107
+ <div class="ys-dialog__footer">
108
+ <div class="ys-dialog__footer-left"><slot name="footer-left" /></div>
109
+ <el-button :disabled="confirmLoading" @click="cancel">{{ cancelText }}</el-button>
110
+ <el-button :type="confirmType" :loading="confirmLoading" :disabled="confirmDisabled" @click="emit('confirm')">{{ confirmText }}</el-button>
111
+ </div>
112
+ </slot>
113
+ </template>
114
+ </el-dialog>
115
+ </template>
116
+
117
+ <style scoped>
118
+ .ys-dialog__footer {
119
+ display: flex;
120
+ gap: 8px;
121
+ align-items: center;
122
+ justify-content: flex-end;
123
+ }
124
+ .ys-dialog__footer-left {
125
+ flex: 1 1 auto;
126
+ min-width: 0;
127
+ color: var(--ys-color-text-3);
128
+ font-size: 12px;
129
+ line-height: 1.6;
130
+ text-align: left;
131
+ }
132
+ .ys-dialog__footer :deep(.el-button + .el-button) {
133
+ margin-left: 0;
134
+ }
135
+ :global(.ys-dialog.el-dialog) {
136
+ max-width: calc(100vw - 24px);
137
+ }
138
+ </style>
@@ -5,6 +5,7 @@ import { computed, ref, watch } from "vue";
5
5
  import { ElMessage } from "element-plus";
6
6
  import { FIELD_SPECS, ENUM_META } from "@ysgroup/contracts";
7
7
  import { enumOptions } from "../tokens-runtime";
8
+ import YsSelect from "./YsSelect.vue";
8
9
 
9
10
  interface FieldSpec {
10
11
  key: string;
@@ -119,6 +120,7 @@ function submit() {
119
120
  :model-value="modelValue"
120
121
  :title="dialogTitle"
121
122
  width="640px"
123
+ :close-on-click-modal="false"
122
124
  @update:model-value="close"
123
125
  >
124
126
  <el-form label-width="150px" label-position="right">
@@ -135,31 +137,21 @@ function submit() {
135
137
  :controls="false"
136
138
  style="width: 100%"
137
139
  />
138
- <el-select
140
+ <YsSelect
139
141
  v-else-if="f.widget === 'enum'"
140
- v-model="form[f.key] as string"
142
+ v-model="form[f.key]"
143
+ :options="optionsOf(f)"
144
+ :clearable="!f.required"
145
+ :value-on-clear="''"
141
146
  style="width: 100%"
142
- >
143
- <el-option
144
- v-for="o in optionsOf(f)"
145
- :key="o.value"
146
- :label="o.label"
147
- :value="o.value"
148
- />
149
- </el-select>
150
- <el-select
147
+ />
148
+ <YsSelect
151
149
  v-else-if="f.widget === 'enum-multi'"
152
- v-model="form[f.key] as string[]"
150
+ v-model="form[f.key]"
151
+ :options="optionsOf(f)"
153
152
  multiple
154
153
  style="width: 100%"
155
- >
156
- <el-option
157
- v-for="o in optionsOf(f)"
158
- :key="o.value"
159
- :label="o.label"
160
- :value="o.value"
161
- />
162
- </el-select>
154
+ />
163
155
  <el-select
164
156
  v-else-if="f.widget === 'tags'"
165
157
  v-model="form[f.key] as string[]"
@@ -0,0 +1,61 @@
1
+ <!-- YsLoadError —— 加载失败态:一行错误文案 + 重试。error 为空不渲染。
2
+ 用法:<YsLoadError :error="catalog.errors.schools" @retry="catalog.refresh('schools')" /> -->
3
+ <script setup lang="ts">
4
+ import { WarningFilled } from "@element-plus/icons-vue";
5
+
6
+ withDefaults(defineProps<{ error?: string | null; retryText?: string }>(), { error: "", retryText: "重试" });
7
+ const emit = defineEmits<{ retry: [] }>();
8
+ </script>
9
+
10
+ <template>
11
+ <div v-if="error" class="ys-load-error" role="alert">
12
+ <el-icon class="ys-load-error__icon" :size="16"><WarningFilled /></el-icon>
13
+ <span class="ys-load-error__text">{{ error }}</span>
14
+ <button class="ys-load-error__retry" type="button" @click="emit('retry')">{{ retryText }}</button>
15
+ </div>
16
+ </template>
17
+
18
+ <style scoped>
19
+ .ys-load-error {
20
+ display: flex;
21
+ gap: 8px;
22
+ align-items: center;
23
+ padding: 8px 12px;
24
+ border: 1px solid color-mix(in srgb, var(--ys-color-danger) 28%, var(--ys-color-border));
25
+ border-radius: var(--ys-radius-m);
26
+ background: color-mix(in srgb, var(--ys-color-danger) 8%, var(--ys-color-bg-elevated));
27
+ color: var(--ys-color-text-1);
28
+ font-size: 13px;
29
+ line-height: 1.5;
30
+ }
31
+ .ys-load-error__icon {
32
+ flex: none;
33
+ color: var(--ys-color-danger);
34
+ }
35
+ .ys-load-error__text {
36
+ flex: 1 1 auto;
37
+ min-width: 0;
38
+ overflow-wrap: anywhere;
39
+ }
40
+ .ys-load-error__retry {
41
+ flex: none;
42
+ padding: 2px 8px;
43
+ border: 0;
44
+ border-radius: var(--ys-radius-s);
45
+ background: transparent;
46
+ color: var(--ys-color-primary);
47
+ font: inherit;
48
+ cursor: pointer;
49
+ }
50
+ .ys-load-error__retry:hover,
51
+ .ys-load-error__retry:focus-visible {
52
+ background: color-mix(in srgb, var(--ys-color-primary) 10%, transparent);
53
+ }
54
+ .ys-load-error__retry:focus {
55
+ outline: none;
56
+ }
57
+ .ys-load-error__retry:focus-visible {
58
+ outline: var(--ys-focus-outline);
59
+ outline-offset: 1px;
60
+ }
61
+ </style>
@@ -290,10 +290,14 @@ html[data-theme="dark"] .ys-login__card::after {
290
290
  background: var(--ys-color-bg-hover);
291
291
  color: var(--ys-color-primary);
292
292
  }
293
- .ys-login__theme-button:focus,
294
- .ys-login__theme-button:focus-visible {
293
+ .ys-login__theme-button:focus {
295
294
  outline: none;
296
295
  }
296
+ .ys-login__theme-button:focus-visible {
297
+ outline: var(--ys-focus-outline);
298
+ outline-offset: -2px;
299
+ color: var(--ys-color-primary);
300
+ }
297
301
  .ys-login__logo {
298
302
  width: 68px;
299
303
  height: 68px;
@@ -380,7 +380,7 @@ defineExpose({ toggle, seekBy, setVolume, setRate });
380
380
  outline: none;
381
381
  }
382
382
  .ys-media:focus-visible {
383
- box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ys-color-primary) 55%, transparent);
383
+ box-shadow: inset 0 0 0 2px var(--ys-color-primary);
384
384
  }
385
385
 
386
386
  /* ---------- 视频 ---------- */
@@ -510,7 +510,7 @@ defineExpose({ toggle, seekBy, setVolume, setRate });
510
510
  outline: none;
511
511
  }
512
512
  .ys-media__btn:focus-visible {
513
- outline: 2px solid color-mix(in srgb, var(--ys-color-primary) 70%, transparent);
513
+ outline: var(--ys-focus-outline);
514
514
  outline-offset: -2px;
515
515
  }
516
516
  .ys-media__btn svg {
@@ -645,7 +645,8 @@ defineExpose({ toggle, seekBy, setVolume, setRate });
645
645
  border: 0;
646
646
  border-radius: 50%;
647
647
  background: var(--ys-color-primary);
648
- color: #fff;
648
+ /* 实心主色上的图标跟明暗走:暗色主色提亮了,白色图标压不住 */
649
+ color: var(--ys-color-on-solid);
649
650
  cursor: pointer;
650
651
  box-shadow: 0 4px 12px -2px color-mix(in srgb, var(--ys-color-primary) 45%, transparent);
651
652
  transition:
@@ -663,8 +664,11 @@ defineExpose({ toggle, seekBy, setVolume, setRate });
663
664
  .ys-media__round:focus {
664
665
  outline: none;
665
666
  }
667
+ /* 按钮本身就是主色,轮廓隔一圈底色再画,才看得出来 */
666
668
  .ys-media__round:focus-visible {
667
- box-shadow: 0 0 0 3px color-mix(in srgb, var(--ys-color-primary) 35%, transparent);
669
+ box-shadow:
670
+ 0 0 0 2px var(--ys-color-bg-elevated),
671
+ 0 0 0 4px var(--ys-color-primary);
668
672
  }
669
673
  .ys-media__round svg {
670
674
  width: 20px;
@@ -191,10 +191,14 @@ function toggleSidebar() {
191
191
  color: var(--ys-color-primary);
192
192
  background: var(--ys-color-bg-hover);
193
193
  }
194
- .ys-layout__toggle:focus,
195
- .ys-layout__toggle:focus-visible {
194
+ .ys-layout__toggle:focus {
196
195
  outline: none;
197
196
  }
197
+ .ys-layout__toggle:focus-visible {
198
+ outline: var(--ys-focus-outline);
199
+ outline-offset: -2px;
200
+ color: var(--ys-color-primary);
201
+ }
198
202
  .ys-layout__toggle-icon {
199
203
  width: 18px;
200
204
  height: 18px;
@@ -645,7 +645,7 @@ defineExpose({ goTo, setZoom });
645
645
  outline: none;
646
646
  }
647
647
  .ys-pdf__thumb:focus-visible {
648
- outline: 2px solid color-mix(in srgb, var(--ys-color-primary) 55%, transparent);
648
+ outline: var(--ys-focus-outline);
649
649
  }
650
650
  .ys-pdf__thumb-paper {
651
651
  position: relative;
@@ -1,57 +1,174 @@
1
+ <!-- YsRowActionMenu —— 表格行「操作」菜单:齿轮按钮点开,按调用方给的顺序列出动作。
2
+ divided 的动作上方画一条分隔线(不会被挪到最后);#extra 插槽的内容排在第一个 divided 动作之前,没有 divided 动作时排在最后。
3
+ 分隔线只出现在两组之间:菜单只剩一项、唯一一项标了 divided、插槽内容为空时都不画,首尾和连续的分隔线由样式兜底隐藏。
4
+ actions 为空且没有 #extra 时不显示齿轮。
5
+ 键盘(WAI-ARIA 菜单按钮):齿轮上 Enter、空格、↓ 打开并聚焦第一项,↑ 打开并聚焦最后一项;菜单里 ↑↓ 循环移动、Home/End 到首尾,
6
+ Enter/空格执行;Esc 关闭并回到齿轮;Tab 关闭菜单,焦点照常移到齿轮的前后一个控件。选中动作、插槽调用 close 后焦点也回到齿轮,
7
+ 动作打开的弹窗关闭时 Element Plus 会把焦点还给齿轮,不会丢在页面末尾。 -->
1
8
  <script setup lang="ts">
2
- import { ref } from "vue";
9
+ import { computed, nextTick, ref, useId, useSlots } from "vue";
3
10
  import { Setting } from "@element-plus/icons-vue";
4
11
 
5
12
  export interface YsRowAction {
6
13
  key: string;
7
14
  label: string;
15
+ /** 悬停和文字颜色,默认 neutral;danger 平时就是危险色。 */
8
16
  tone?: "primary" | "accent" | "warning" | "success" | "neutral" | "danger";
9
17
  disabled?: boolean;
18
+ /** 在这个动作上方画分隔线。 */
10
19
  divided?: boolean;
11
20
  }
12
21
 
13
- defineProps<{ actions: YsRowAction[]; ariaLabel?: string }>();
22
+ const props = withDefaults(
23
+ defineProps<{
24
+ actions: YsRowAction[];
25
+ /** 触发按钮的无障碍名称,默认「操作」。 */
26
+ ariaLabel?: string;
27
+ /** 菜单宽度(像素),默认 150。 */
28
+ menuWidth?: number;
29
+ }>(),
30
+ { ariaLabel: "", menuWidth: 150 },
31
+ );
14
32
  const emit = defineEmits<{ action: [key: string] }>();
33
+ const slots = useSlots();
15
34
  const visible = ref(false);
35
+ const triggerButton = ref<HTMLButtonElement>();
36
+ const menu = ref<HTMLElement>();
37
+ const menuId = `ys-row-action-${useId()}`;
38
+
39
+ /** 菜单里能聚焦的项:自带动作和 #extra 插槽里的按钮,跳过禁用的。 */
40
+ function items(): HTMLElement[] {
41
+ return Array.from(menu.value?.querySelectorAll<HTMLElement>("button, [role='menuitem']") ?? []).filter(
42
+ (el) => !(el as HTMLButtonElement).disabled && el.getAttribute("aria-disabled") !== "true",
43
+ );
44
+ }
45
+
46
+ /** 打开后聚焦第一项或最后一项。浮层首次打开时内容可能晚一帧才挂上,等一帧再找。 */
47
+ async function focusItem(which: "first" | "last") {
48
+ await nextTick();
49
+ let list = items();
50
+ if (!list.length) {
51
+ await new Promise((resolve) => requestAnimationFrame(resolve));
52
+ list = items();
53
+ }
54
+ list[which === "first" ? 0 : list.length - 1]?.focus();
55
+ }
56
+
57
+ function onTriggerKeydown(event: KeyboardEvent) {
58
+ if (!["Enter", " ", "ArrowDown", "ArrowUp"].includes(event.key)) return;
59
+ // 自己处理:阻止按钮的原生点击,否则 Enter/空格会再触发一次开关
60
+ event.preventDefault();
61
+ visible.value = true;
62
+ void focusItem(event.key === "ArrowUp" ? "last" : "first");
63
+ }
64
+
65
+ /** 关闭菜单;焦点在菜单里时还给齿轮,避免落到 body 上(菜单挂在 body 末尾)。 */
66
+ function close() {
67
+ const focusInside = !!menu.value?.contains(document.activeElement);
68
+ visible.value = false;
69
+ if (focusInside) triggerButton.value?.focus();
70
+ }
71
+
72
+ function onMenuKeydown(event: KeyboardEvent) {
73
+ if (event.key === "Escape") {
74
+ event.preventDefault();
75
+ event.stopPropagation();
76
+ close();
77
+ return;
78
+ }
79
+ if (event.key === "Tab") {
80
+ // 不阻止默认行为:先把焦点放回齿轮,浏览器再从齿轮往前或往后移
81
+ close();
82
+ return;
83
+ }
84
+ if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
85
+ const list = items();
86
+ if (!list.length) return;
87
+ event.preventDefault();
88
+ const index = list.indexOf(document.activeElement as HTMLElement);
89
+ const next =
90
+ event.key === "Home"
91
+ ? 0
92
+ : event.key === "End"
93
+ ? list.length - 1
94
+ : (index + (event.key === "ArrowDown" ? 1 : -1) + list.length) % list.length;
95
+ list[next]?.focus();
96
+ }
97
+
98
+ /** #extra 插槽的位置:第一个 divided 动作之前;没有就在最后。 */
99
+ const extraIndex = computed(() => {
100
+ const index = props.actions.findIndex((action) => action.divided);
101
+ return index < 0 ? props.actions.length : index;
102
+ });
103
+
104
+ /** 分隔线只画在两组之间:第一个动作上方不画;传了 #extra 且排在它前面时才画,插槽渲染为空时由下方 CSS 兜底隐藏。 */
105
+ const firstVisible = computed(() => (extraIndex.value === 0 && slots.extra ? -1 : 0));
16
106
 
17
107
  function select(action: YsRowAction) {
18
108
  if (action.disabled) return;
19
- visible.value = false;
109
+ // 先还焦点再通知:动作若打开弹窗,弹窗记下的「之前的焦点」就是齿轮
110
+ close();
20
111
  emit("action", action.key);
21
112
  }
22
113
  </script>
23
114
 
24
115
  <template>
116
+ <!-- 没有任何动作、也没有 #extra 内容时不显示齿轮(规范:没有可做的操作就不给入口) -->
25
117
  <el-popover
118
+ v-if="actions.length || $slots.extra"
26
119
  :visible="visible"
27
120
  placement="left-start"
28
121
  :fallback-placements="['left', 'left-end', 'top-end', 'bottom-end']"
29
- :width="150"
122
+ :width="menuWidth"
30
123
  :offset="8"
31
124
  :hide-after="0"
32
125
  :teleported="true"
126
+ :trigger-keys="[]"
33
127
  trigger="click"
34
128
  popper-class="ys-action-popover"
35
129
  @update:visible="visible = $event"
36
130
  >
131
+ <!-- 包一层 span 给 EP 挂触发器:EP 会改写参考元素的 aria-*(按 tooltip 处理),按钮自己的菜单按钮语义才能保留 -->
37
132
  <template #reference
38
- ><button class="ys-row-action__trigger" type="button" :aria-label="ariaLabel || '操作'">
133
+ ><span class="ys-row-action__anchor"
134
+ ><button
135
+ ref="triggerButton"
136
+ class="ys-row-action__trigger"
137
+ type="button"
138
+ :aria-label="ariaLabel || '操作'"
139
+ aria-haspopup="menu"
140
+ :aria-expanded="visible"
141
+ :aria-controls="menuId"
142
+ @keydown="onTriggerKeydown"
143
+ >
39
144
  <el-icon :size="17"><Setting /></el-icon></button
40
- ></template>
41
- <nav class="ys-row-action__menu" :aria-label="ariaLabel || '操作菜单'">
42
- <template v-for="action in actions.filter((item) => !item.divided)" :key="action.key">
43
- <button class="ys-row-action__item" :class="`is-${action.tone || 'neutral'}`" type="button" :disabled="action.disabled" @click="select(action)">{{ action.label }}</button>
145
+ ></span></template>
146
+ <div :id="menuId" ref="menu" class="ys-row-action__menu" role="menu" :aria-label="ariaLabel || '操作菜单'" @keydown="onMenuKeydown">
147
+ <template v-for="(action, index) in actions" :key="action.key">
148
+ <slot v-if="index === extraIndex" name="extra" :close="close" />
149
+ <div v-if="action.divided && index > firstVisible" class="ys-row-action__divider" role="separator" />
150
+ <button
151
+ class="ys-row-action__item"
152
+ :class="`is-${action.tone || 'neutral'}`"
153
+ type="button"
154
+ role="menuitem"
155
+ tabindex="-1"
156
+ :disabled="action.disabled"
157
+ @click="select(action)"
158
+ >
159
+ {{ action.label }}
160
+ </button>
44
161
  </template>
45
- <slot name="extra" :close="() => (visible = false)" />
46
- <template v-for="action in actions.filter((item) => item.divided)" :key="action.key">
47
- <div class="ys-row-action__divider" />
48
- <button class="ys-row-action__item" :class="`is-${action.tone || 'neutral'}`" type="button" :disabled="action.disabled" @click="select(action)">{{ action.label }}</button>
49
- </template>
50
- </nav>
162
+ <slot v-if="extraIndex === actions.length" name="extra" :close="close" />
163
+ </div>
51
164
  </el-popover>
52
165
  </template>
53
166
 
54
167
  <style scoped>
168
+ .ys-row-action__anchor {
169
+ display: inline-flex;
170
+ vertical-align: middle;
171
+ }
55
172
  .ys-row-action__trigger {
56
173
  display: inline-grid;
57
174
  place-items: center;
@@ -67,11 +184,18 @@ function select(action: YsRowAction) {
67
184
  cursor: pointer;
68
185
  }
69
186
  .ys-row-action__trigger:hover,
70
- .ys-row-action__trigger:focus-visible {
71
- outline: none;
187
+ .ys-row-action__trigger[aria-expanded="true"] {
72
188
  color: var(--ys-color-primary);
73
189
  background: color-mix(in srgb, var(--ys-color-primary) 9%, transparent);
74
190
  }
191
+ .ys-row-action__trigger:focus {
192
+ outline: none;
193
+ }
194
+ .ys-row-action__trigger:focus-visible {
195
+ outline: var(--ys-focus-outline);
196
+ outline-offset: -2px;
197
+ color: var(--ys-color-primary);
198
+ }
75
199
  .ys-row-action__menu {
76
200
  display: grid;
77
201
  gap: 3px;
@@ -98,10 +222,22 @@ function select(action: YsRowAction) {
98
222
  background: color-mix(in srgb, var(--item-color) 10%, transparent);
99
223
  color: var(--item-color);
100
224
  }
225
+ /* 键盘移到的项除了底色再画轮廓:底色只有 10%,单靠它在暗色下不够明显 */
226
+ .ys-row-action__item:focus-visible {
227
+ outline: var(--ys-focus-outline);
228
+ outline-offset: -2px;
229
+ }
101
230
  .ys-row-action__item:disabled {
102
231
  opacity: 0.45;
103
232
  cursor: not-allowed;
104
233
  }
234
+ .ys-row-action__item:disabled:hover {
235
+ background: transparent;
236
+ color: var(--ys-color-text-2);
237
+ }
238
+ .ys-row-action__item.is-danger:disabled:hover {
239
+ color: var(--ys-color-danger);
240
+ }
105
241
  .ys-row-action__item.is-primary {
106
242
  --item-color: var(--ys-color-primary);
107
243
  }
@@ -134,6 +270,12 @@ function select(action: YsRowAction) {
134
270
  text-align: left;
135
271
  cursor: pointer;
136
272
  }
273
+ /* 兜底:分隔线不出现在菜单首尾、不连续出现。插槽渲染为空、调用方把唯一一项标成 divided 时都不会多一条线。 */
274
+ .ys-row-action__divider:first-child,
275
+ .ys-row-action__divider:last-child,
276
+ .ys-row-action__divider + .ys-row-action__divider {
277
+ display: none;
278
+ }
137
279
  .ys-row-action__divider {
138
280
  height: 1px;
139
281
  margin: 3px 4px;
@@ -0,0 +1,273 @@
1
+ <!-- YsSelect —— 带拼音搜索的下拉:中文、拼音首字母、全拼、编号都能搜(规则同 @ysgroup/core 的 ysMatch)。
2
+ 选项多于 virtualThreshold 时自动改用 el-select-v2 虚拟滚动;其余属性和事件透传给里面的 el-select / el-select-v2。
3
+ 选项的值必须是字符串、数字或布尔值,同一个下拉里不能重复。 -->
4
+ <script setup lang="ts" generic="T">
5
+ import { computed, h, onBeforeUnmount, ref, withDirectives, type VNode } from "vue";
6
+ import { useYsOptionFilter } from "../optionFilter";
7
+ import { vTip } from "../vTip";
8
+
9
+ interface Entry {
10
+ value: unknown;
11
+ label: string;
12
+ hint: string;
13
+ disabled: boolean;
14
+ group: string;
15
+ option: T;
16
+ }
17
+
18
+ const props = withDefaults(
19
+ defineProps<{
20
+ /** 选中的值;多选时是数组。 */
21
+ modelValue?: unknown;
22
+ options: readonly T[];
23
+ /** 选项里当作值的字段。选项本身是字符串或数字时,值和文字都是它自己。 */
24
+ valueKey?: string;
25
+ /** 选项里当作显示文字的字段。 */
26
+ labelKey?: string;
27
+ /** 自己算显示文字,给了就不用 labelKey。 */
28
+ label?: (option: T) => string;
29
+ /** 额外参与搜索的内容(编号、别名、工号……),可返回数组。 */
30
+ searchText?: (option: T) => unknown;
31
+ /** 选项右侧的次要说明(工号、公司……),也参与搜索。 */
32
+ hint?: (option: T) => string;
33
+ /** 这个选项是否不可选。不传时看选项自己的 disabled 字段。 */
34
+ optionDisabled?: (option: T) => boolean;
35
+ /** 分组标题;按首次出现的顺序分组,返回空串的选项不进分组。 */
36
+ groupBy?: (option: T) => string;
37
+ multiple?: boolean;
38
+ filterable?: boolean;
39
+ clearable?: boolean;
40
+ placeholder?: string;
41
+ /** 不传时跟随外层 el-form 的 disabled。 */
42
+ disabled?: boolean;
43
+ /** 选项数超过它改用虚拟滚动。 */
44
+ virtualThreshold?: number;
45
+ popperClass?: string;
46
+ }>(),
47
+ {
48
+ modelValue: undefined,
49
+ valueKey: "value",
50
+ labelKey: "label",
51
+ label: undefined,
52
+ searchText: undefined,
53
+ hint: undefined,
54
+ optionDisabled: undefined,
55
+ groupBy: undefined,
56
+ filterable: true,
57
+ clearable: true,
58
+ placeholder: "请选择",
59
+ disabled: undefined,
60
+ virtualThreshold: 200,
61
+ popperClass: "",
62
+ },
63
+ );
64
+
65
+ const emit = defineEmits<{
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ "update:modelValue": [value: any];
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ change: [value: any];
70
+ "visible-change": [visible: boolean];
71
+ clear: [];
72
+ }>();
73
+
74
+ defineSlots<{
75
+ /** 自定义选项内容。 */
76
+ option?: (scope: { option: T }) => unknown;
77
+ /** 没有选项或没有匹配时的内容。 */
78
+ empty?: () => unknown;
79
+ /** 输入框前缀。 */
80
+ prefix?: () => unknown;
81
+ }>();
82
+
83
+ /** 收起动画结束后再恢复全部选项,收起过程中列表不跳。 */
84
+ const CLOSE_RESET_MS = 300;
85
+
86
+ function fieldOf(option: T, key: string): unknown {
87
+ return option !== null && typeof option === "object" ? (option as Record<string, unknown>)[key] : option;
88
+ }
89
+
90
+ const entries = computed<Entry[]>(() =>
91
+ props.options.map((option) => {
92
+ const value = fieldOf(option, props.valueKey);
93
+ const label = props.label ? props.label(option) : fieldOf(option, props.labelKey);
94
+ const ownDisabled = option !== null && typeof option === "object" && (option as { disabled?: unknown }).disabled === true;
95
+ return {
96
+ value,
97
+ label: String(label ?? value ?? ""),
98
+ hint: String(props.hint?.(option) ?? ""),
99
+ disabled: props.optionDisabled ? !!props.optionDisabled(option) : ownDisabled,
100
+ group: String(props.groupBy?.(option) ?? ""),
101
+ option,
102
+ };
103
+ }),
104
+ );
105
+ const byValue = computed(() => new Map(entries.value.map((entry) => [entry.value, entry])));
106
+
107
+ const { keyword, filtered, filterMethod, reset } = useYsOptionFilter(entries, (entry) => [entry.label, entry.hint, props.searchText?.(entry.option)]);
108
+
109
+ const groups = computed<{ label: string; entries: Entry[] }[]>(() => {
110
+ if (!props.groupBy) return [{ label: "", entries: filtered.value }];
111
+ const list: { label: string; entries: Entry[] }[] = [];
112
+ const byLabel = new Map<string, Entry[]>();
113
+ for (const entry of filtered.value) {
114
+ let bucket = byLabel.get(entry.group);
115
+ if (!bucket) {
116
+ bucket = [];
117
+ byLabel.set(entry.group, bucket);
118
+ list.push({ label: entry.group, entries: bucket });
119
+ }
120
+ bucket.push(entry);
121
+ }
122
+ return list;
123
+ });
124
+
125
+ const virtual = computed(() => props.options.length > props.virtualThreshold);
126
+ /** el-select-v2 的 options:分组是 { value, label, options }(value 只为不被当成重复值),其余直接是选项。 */
127
+ const virtualOptions = computed(() =>
128
+ groups.value.flatMap<Entry | { value: string; label: string; options: Entry[] }>((group) =>
129
+ group.label ? [{ value: `ys-select-group:${group.label}`, label: group.label, options: group.entries }] : group.entries,
130
+ ),
131
+ );
132
+
133
+ /** el-select-v2 多选时不接受空值。 */
134
+ const innerValue = computed(() => (props.multiple && !Array.isArray(props.modelValue) ? [] : props.modelValue));
135
+ const emptyText = computed(() => (keyword.value.trim() && props.options.length ? "无匹配数据" : "暂无数据"));
136
+ /** 虚拟滚动的下拉宽度由 el-select-v2 自己算,只给普通下拉限宽。 */
137
+ const popper = computed(() => ["ys-select-popper", virtual.value ? "" : "is-fit", props.popperClass].filter(Boolean).join(" "));
138
+
139
+ /** 输入框和标签里显示的文字:从全部选项里找,选中的值被搜索过滤掉时也能显示名称,不会变成原始值。 */
140
+ function labelOf(value: unknown, fallback: unknown): string {
141
+ return byValue.value.get(value)?.label ?? String(fallback ?? "");
142
+ }
143
+
144
+ function OptionText(scope: { entry: Entry }): VNode[] {
145
+ const { label, hint } = scope.entry;
146
+ const nodes = [withDirectives(h("span", { class: "ys-select-option__label" }, label), [[vTip, label, "", { overflow: true }]])];
147
+ if (hint) nodes.push(h("span", { class: "ys-select-option__hint" }, hint));
148
+ return nodes;
149
+ }
150
+
151
+ let resetTimer: ReturnType<typeof setTimeout> | undefined;
152
+ function onVisibleChange(visible: boolean) {
153
+ clearTimeout(resetTimer);
154
+ if (!visible) resetTimer = setTimeout(reset, CLOSE_RESET_MS);
155
+ emit("visible-change", visible);
156
+ }
157
+ onBeforeUnmount(() => clearTimeout(resetTimer));
158
+
159
+ const inner = ref<{ focus?: () => void; blur?: () => void } | null>(null);
160
+ defineExpose({
161
+ focus: () => inner.value?.focus?.(),
162
+ blur: () => inner.value?.blur?.(),
163
+ });
164
+ </script>
165
+
166
+ <template>
167
+ <el-select-v2
168
+ v-if="virtual"
169
+ ref="inner"
170
+ class="ys-select"
171
+ :model-value="innerValue"
172
+ :options="virtualOptions"
173
+ :multiple="multiple"
174
+ :filterable="filterable"
175
+ :filter-method="filterable ? filterMethod : undefined"
176
+ :clearable="clearable"
177
+ :placeholder="placeholder"
178
+ :disabled="disabled"
179
+ :collapse-tags="multiple"
180
+ :collapse-tags-tooltip="multiple"
181
+ :no-data-text="emptyText"
182
+ no-match-text="无匹配数据"
183
+ :popper-class="popper"
184
+ @update:model-value="emit('update:modelValue', $event)"
185
+ @change="emit('change', $event)"
186
+ @visible-change="onVisibleChange"
187
+ @clear="emit('clear')"
188
+ >
189
+ <template #default="{ item }">
190
+ <span class="ys-select-option">
191
+ <slot name="option" :option="(item as Entry).option"><OptionText :entry="item as Entry" /></slot>
192
+ </span>
193
+ </template>
194
+ <template #label="{ label: current, value }"
195
+ ><span>{{ labelOf(value, current) }}</span></template
196
+ >
197
+ <template v-if="$slots.prefix" #prefix><slot name="prefix" /></template>
198
+ <template v-if="$slots.empty" #empty><slot name="empty" /></template>
199
+ </el-select-v2>
200
+ <el-select
201
+ v-else
202
+ ref="inner"
203
+ class="ys-select"
204
+ :model-value="innerValue"
205
+ :multiple="multiple"
206
+ :filterable="filterable"
207
+ :filter-method="filterable ? filterMethod : undefined"
208
+ :clearable="clearable"
209
+ :placeholder="placeholder"
210
+ :disabled="disabled"
211
+ :collapse-tags="multiple"
212
+ :collapse-tags-tooltip="multiple"
213
+ :no-data-text="emptyText"
214
+ no-match-text="无匹配数据"
215
+ :popper-class="popper"
216
+ @update:model-value="emit('update:modelValue', $event)"
217
+ @change="emit('change', $event)"
218
+ @visible-change="onVisibleChange"
219
+ @clear="emit('clear')"
220
+ >
221
+ <template v-for="group in groups" :key="group.label">
222
+ <el-option-group v-if="group.label" :label="group.label">
223
+ <el-option v-for="entry in group.entries" :key="String(entry.value)" :label="entry.label" :value="entry.value" :disabled="entry.disabled">
224
+ <span class="ys-select-option">
225
+ <slot name="option" :option="entry.option"><OptionText :entry="entry" /></slot>
226
+ </span>
227
+ </el-option>
228
+ </el-option-group>
229
+ <template v-else>
230
+ <el-option v-for="entry in group.entries" :key="String(entry.value)" :label="entry.label" :value="entry.value" :disabled="entry.disabled">
231
+ <span class="ys-select-option">
232
+ <slot name="option" :option="entry.option"><OptionText :entry="entry" /></slot>
233
+ </span>
234
+ </el-option>
235
+ </template>
236
+ </template>
237
+ <template #label="{ label: current, value }"
238
+ ><span>{{ labelOf(value, current) }}</span></template
239
+ >
240
+ <template v-if="$slots.prefix" #prefix><slot name="prefix" /></template>
241
+ <template v-if="$slots.empty" #empty><slot name="empty" /></template>
242
+ </el-select>
243
+ </template>
244
+
245
+ <style>
246
+ /* 选项在弹出层里(挂到 body),不能用 scoped。 */
247
+ .ys-select-option {
248
+ display: flex;
249
+ gap: 12px;
250
+ align-items: center;
251
+ min-width: 0;
252
+ }
253
+ .ys-select-option__label {
254
+ flex: 1 1 auto;
255
+ min-width: 0;
256
+ overflow: hidden;
257
+ text-overflow: ellipsis;
258
+ white-space: nowrap;
259
+ }
260
+ .ys-select-option__hint {
261
+ flex: 0 1 auto;
262
+ max-width: 45%;
263
+ overflow: hidden;
264
+ color: var(--ys-color-text-3);
265
+ font-size: 12px;
266
+ text-overflow: ellipsis;
267
+ white-space: nowrap;
268
+ }
269
+ /* 选项文字过长时省略,不把下拉撑出屏幕。 */
270
+ .ys-select-popper.is-fit .el-select-dropdown {
271
+ max-width: min(560px, calc(100vw - 24px));
272
+ }
273
+ </style>
@@ -446,7 +446,7 @@ onBeforeUnmount(() => {
446
446
  outline: none;
447
447
  }
448
448
  .ys-sheet__tab:focus-visible {
449
- outline: 2px solid color-mix(in srgb, var(--ys-color-primary) 55%, transparent);
449
+ outline: var(--ys-focus-outline);
450
450
  outline-offset: -2px;
451
451
  }
452
452
  .ys-sheet__tab.is-active {
@@ -0,0 +1,87 @@
1
+ <!-- YsTreeSelect —— 带拼音搜索的树下拉:包 el-tree-select,搜索规则同 YsSelect;命中节点的祖先一并保留。
2
+ 其余属性和事件(show-checkbox、default-expanded-keys、node-click……)透传给 el-tree-select。 -->
3
+ <script setup lang="ts">
4
+ import { computed, ref } from "vue";
5
+ import { ysTreeFilter } from "../optionFilter";
6
+
7
+ type TreeNodeData = Record<string, unknown>;
8
+
9
+ const props = withDefaults(
10
+ defineProps<{
11
+ /** 选中的值;多选时是数组。 */
12
+ modelValue?: unknown;
13
+ data: TreeNodeData[];
14
+ /** 节点里当作值的字段。 */
15
+ nodeKey?: string;
16
+ /** 节点里当作显示文字的字段。 */
17
+ labelKey?: string;
18
+ /** 节点里放子节点的字段。 */
19
+ childrenKey?: string;
20
+ /** 额外参与搜索的内容(编号、别名……),可返回数组。 */
21
+ searchText?: (data: TreeNodeData) => unknown;
22
+ clearable?: boolean;
23
+ filterable?: boolean;
24
+ /** 父子不关联:任何一级都能选。 */
25
+ checkStrictly?: boolean;
26
+ defaultExpandAll?: boolean;
27
+ multiple?: boolean;
28
+ placeholder?: string;
29
+ /** 不传时跟随外层 el-form 的 disabled。 */
30
+ disabled?: boolean;
31
+ /** el-tree 的 props(disabled、isLeaf 等字段映射);label、children 已按 labelKey、childrenKey 设好。 */
32
+ props?: Record<string, unknown>;
33
+ }>(),
34
+ {
35
+ modelValue: undefined,
36
+ nodeKey: "value",
37
+ labelKey: "label",
38
+ childrenKey: "children",
39
+ searchText: undefined,
40
+ clearable: true,
41
+ filterable: true,
42
+ placeholder: "请选择",
43
+ disabled: undefined,
44
+ props: undefined,
45
+ },
46
+ );
47
+
48
+ const emit = defineEmits<{
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ "update:modelValue": [value: any];
51
+ }>();
52
+
53
+ const treeProps = computed(() => ({ label: props.labelKey, children: props.childrenKey, ...props.props }));
54
+ const filterNode = computed(() => ysTreeFilter<TreeNodeData>((data) => [data[props.labelKey], props.searchText?.(data)]));
55
+ /** el-select 多选时要数组。 */
56
+ const innerValue = computed(() => (props.multiple && !Array.isArray(props.modelValue) ? [] : props.modelValue));
57
+
58
+ /** 里面的 el-tree-select 实例:需要 getCheckedNodes、getNode 等树方法时用。 */
59
+ const treeSelect = ref<Record<string, unknown> | null>(null);
60
+ defineExpose({ treeSelect });
61
+ </script>
62
+
63
+ <template>
64
+ <el-tree-select
65
+ ref="treeSelect"
66
+ class="ys-tree-select"
67
+ :model-value="innerValue"
68
+ :data="data"
69
+ :node-key="nodeKey"
70
+ :props="treeProps"
71
+ :multiple="multiple"
72
+ :filterable="filterable"
73
+ :filter-node-method="filterNode"
74
+ :clearable="clearable"
75
+ :check-strictly="checkStrictly"
76
+ :default-expand-all="defaultExpandAll"
77
+ :placeholder="placeholder"
78
+ :disabled="disabled"
79
+ :collapse-tags="multiple"
80
+ :collapse-tags-tooltip="multiple"
81
+ no-data-text="暂无数据"
82
+ no-match-text="无匹配数据"
83
+ @update:model-value="emit('update:modelValue', $event)"
84
+ >
85
+ <template v-for="(_, name) in $slots" #[name]="scope" :key="name"><slot :name="name" v-bind="scope ?? {}" /></template>
86
+ </el-tree-select>
87
+ </template>
package/src/dialog.ts ADDED
@@ -0,0 +1,45 @@
1
+ /* 弹窗标题与确认框的统一写法。 */
2
+ import { ElMessageBox } from "element-plus";
3
+
4
+ /**
5
+ * 弹窗标题「动作(编号|名称)」:dialogTitle("编辑", row.code, row.name) → 「编辑(A001|张三)」。
6
+ * 空的部分(null、undefined、空白)跳过,重复的只留一个;全空时只返回动作。
7
+ */
8
+ export function dialogTitle(action: string, ...parts: unknown[]): string {
9
+ const seen: string[] = [];
10
+ for (const part of parts) {
11
+ const text = String(part ?? "").trim();
12
+ if (text && !seen.includes(text)) seen.push(text);
13
+ }
14
+ return seen.length ? `${action}(${seen.join("|")})` : action;
15
+ }
16
+
17
+ export interface YsConfirmOptions {
18
+ /** 标题,默认「请确认」。 */
19
+ title?: string;
20
+ /** 危险操作(删除、作废……):确认按钮用危险色,图标用错误色。 */
21
+ danger?: boolean;
22
+ /** 确认按钮文字,默认「确定」。 */
23
+ confirmText?: string;
24
+ /** 取消按钮文字,默认「取消」。 */
25
+ cancelText?: string;
26
+ }
27
+
28
+ /**
29
+ * 统一的确认框:确认返回 true;点取消、右上角关闭、按 Esc 都返回 false,不抛异常。点遮罩不关闭。
30
+ * if (!(await ysConfirm(`删除「${row.name}」后不可恢复,确定删除吗?`, { title: "删除学校", danger: true, confirmText: "删除" }))) return;
31
+ */
32
+ export async function ysConfirm(message: string, options: YsConfirmOptions = {}): Promise<boolean> {
33
+ try {
34
+ await ElMessageBox.confirm(message, options.title ?? "请确认", {
35
+ type: options.danger ? "error" : "warning",
36
+ confirmButtonText: options.confirmText ?? "确定",
37
+ cancelButtonText: options.cancelText ?? "取消",
38
+ confirmButtonClass: options.danger ? "el-button--danger" : "",
39
+ closeOnClickModal: false,
40
+ });
41
+ return true;
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
package/src/index.ts CHANGED
@@ -6,6 +6,12 @@ export { default as YsTablePagination } from "./components/YsTablePagination.vue
6
6
  export { default as YsRowActionMenu } from "./components/YsRowActionMenu.vue";
7
7
  export type { YsRowAction } from "./components/YsRowActionMenu.vue";
8
8
  export { default as YsFormDialog } from "./components/YsFormDialog.vue";
9
+ export { default as YsSelect } from "./components/YsSelect.vue";
10
+ export { default as YsTreeSelect } from "./components/YsTreeSelect.vue";
11
+ export { useYsOptionFilter, ysTreeFilter, type YsOptionFilter } from "./optionFilter";
12
+ export { default as YsDialog } from "./components/YsDialog.vue";
13
+ export { dialogTitle, ysConfirm, type YsConfirmOptions } from "./dialog";
14
+ export { default as YsLoadError } from "./components/YsLoadError.vue";
9
15
  export { default as YsPageLayout } from "./components/YsPageLayout.vue";
10
16
  export { default as YsAppToolbar } from "./components/YsAppToolbar.vue";
11
17
  export { default as YsSideMenu } from "./components/YsSideMenu.vue";
@@ -19,6 +25,7 @@ export { default as YsServiceStatus } from "./components/YsServiceStatus.vue";
19
25
  export { default as YsSettingsCenterDialog } from "./components/YsSettingsCenterDialog.vue";
20
26
  export { default as YsPortalGrid } from "./components/YsPortalGrid.vue";
21
27
  export { default as YsRoleTag } from "./components/YsRoleTag.vue";
28
+ export { default as YsAmount } from "./components/YsAmount.vue";
22
29
  export { default as YsBoolMark } from "./components/YsBoolMark.vue";
23
30
  export { default as YsSegmented } from "./components/YsSegmented.vue";
24
31
  export { default as YsCountBadge } from "./components/YsCountBadge.vue";
@@ -0,0 +1,58 @@
1
+ /* 下拉与树的拼音搜索:规则同 @ysgroup/core 的 ysMatch(中文、拼音首字母、全拼、数字千分位、全角半角、空格分隔多个关键词)。
2
+ *
3
+ * 一般直接用 YsSelect / YsTreeSelect;必须手写 el-select、el-tree 时用这里的两个函数:
4
+ *
5
+ * const { filtered, filterMethod, reset } = useYsOptionFilter(() => props.users, (user) => [user.name, user.code]);
6
+ * <el-select v-model="value" filterable :filter-method="filterMethod" @visible-change="(open) => !open && reset()">
7
+ * <el-option v-for="user in filtered" :key="user.id" :label="user.name" :value="user.id" />
8
+ * </el-select>
9
+ *
10
+ * <el-tree ref="tree" :data="data" :filter-node-method="ysTreeFilter((node) => [node.label, node.code])" />
11
+ * watch(keyword, (value) => tree.value?.filter(value));
12
+ */
13
+ import { computed, ref, toValue, type ComputedRef, type MaybeRefOrGetter, type Ref } from "vue";
14
+ import { searchTokens, ysMatch, ysSearchText } from "@ysgroup/core";
15
+
16
+ export interface YsOptionFilter<T> {
17
+ /** 当前关键词。 */
18
+ keyword: Ref<string>;
19
+ /** 命中的选项,保持原顺序;关键词为空时是全部选项。 */
20
+ filtered: ComputedRef<T[]>;
21
+ /** 直接给 el-select / el-select-v2 的 filter-method。 */
22
+ filterMethod: (query: string) => void;
23
+ /** 清空关键词(下拉收起后调用)。 */
24
+ reset: () => void;
25
+ }
26
+
27
+ /**
28
+ * 按拼音过滤选项。textOf 返回这个选项参与搜索的内容(名称、编号、别名……可返回数组,空值自动跳过)。
29
+ * 搜索文本只在 options 变化时拼一次,按键时不重拼。
30
+ */
31
+ export function useYsOptionFilter<T>(options: MaybeRefOrGetter<readonly T[] | null | undefined>, textOf: (option: T) => unknown): YsOptionFilter<T> {
32
+ const keyword = ref("");
33
+ const indexed = computed(() => (toValue(options) ?? []).map((option) => ({ option, text: ysSearchText(textOf(option)) })));
34
+ const filtered = computed<T[]>(() => {
35
+ const query = keyword.value;
36
+ if (!searchTokens(query).length) return [...(toValue(options) ?? [])];
37
+ return indexed.value.filter((item) => ysMatch(item.text, query)).map((item) => item.option);
38
+ });
39
+ return {
40
+ keyword,
41
+ filtered,
42
+ filterMethod: (query: string) => {
43
+ keyword.value = query ?? "";
44
+ },
45
+ reset: () => {
46
+ keyword.value = "";
47
+ },
48
+ };
49
+ }
50
+
51
+ /**
52
+ * 返回可直接给 el-tree / el-tree-select 的 filter-node-method。
53
+ * textOf 返回节点参与搜索的内容,不传时用节点的 label。命中节点的祖先由 el-tree 自动保留;关键词为空时全部显示。
54
+ */
55
+ export function ysTreeFilter<D = Record<string, unknown>>(textOf?: (data: D) => unknown): (keyword: string, data: D) => boolean {
56
+ const text = textOf ?? ((data: D) => (data as { label?: unknown } | null)?.label);
57
+ return (keyword, data) => !keyword || ysMatch(ysSearchText(text(data)), keyword);
58
+ }
@@ -93,7 +93,7 @@
93
93
  }
94
94
 
95
95
  .ys-viewer__btn:focus-visible {
96
- outline: 2px solid color-mix(in srgb, var(--ys-color-primary) 55%, transparent);
96
+ outline: var(--ys-focus-outline);
97
97
  outline-offset: -2px;
98
98
  }
99
99