@ysgroup/ui 0.1.63 → 0.2.0

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.
@@ -1,29 +1,33 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
- * 月历:每天右上角一个状态标签,底色跟着状态走,一眼分清能不能交易、要不要上班。
3
+ * 月历:一种综合样式,同时回答「要不要上班」「开不开市」「当晚有没有夜盘」。
4
4
  *
5
- * - mark="trading" 交易日视图:交易日浅绿底、蓝色「交易日」标签(showOrdinal 时旁边写本月第几个,默认不写);
6
- * 休市日(周末、放假、法定补班的周末)不上底色,写灰色「休市」。
7
- * - mark="work" 工作日视图:工作日和法定补班(调休上班的周末)浅绿底,分别写「工作日」「法定补班」
8
- * (实心标签,最醒目);周末不上底色写「休息」,法定放假浅橙底写「放假」和节日名。
9
- * - 不传 mark(或 mark="none")是默认视图:只当普通月历用,只显示日期和事件。
5
+ * - 底色只看上不上班:工作日和法定补班(调休上班的周末)浅绿,法定放假浅橙,普通周末不上底色。
6
+ * - 右上角先写上班类标签、再写「开市」:工作日「上班」(绿描边),法定补班「补班」(绿实心,最醒目),放假「放假」(橙描边);
7
+ * 交易日后面再加「开市」(蓝色浅底)。周末不写字,日期数字变灰。放不下时「开市」自动退到「上班」下面,不截断。
8
+ * - 标签下面一行:交易所额外休市写「交易所休市」(灰),法定补班写「节日名调休」,放假写节日名。
9
+ * - 右下角是格子里最后一个元素「夜盘」(靛紫实心),表示当天晚上 21:00 起有期货夜盘(计入下一个交易日);
10
+ * 没有夜盘、夜盘未知都不写,原因看 YsCalendarDayCard。showOrdinal 时左下角写本月第几个交易日(默认不写)。
10
11
  * - 上月、下月的格子只留淡底色和日期,不写标签。
11
- * - 标签文字可以用 labels 改(如把「法定补班」改成「调休上班」);showLabel、showOrdinal 控制标签和序号显不显示。
12
+ * - 标签文字可以用 labels 改;showLabel 关掉右上角标签(底色、夜盘照常)。
12
13
  * - 日期信息(days)由服务端 ys_base.calendar 下发,组件只显示,不自己按周一到周五猜;某天 covered 为 false 表示这一年
13
- * 还没有放假安排,顶部写明、格子不标状态。序号由 @ysgroup/core 的 ysTradingMarks 按 trading 字段推出,只对完整月份标。
14
- * - 图例可以点:悬停或点一项,只突出这一类日子,再点一次取消。
14
+ * 还没有放假安排,顶部写明、格子不标状态。没有 days 时就是普通月历,只显示日期和事件。
15
+ * - 图例按条件突出:上班(含补班)、补班、放假、开市、夜盘;悬停临时突出,点一下固定,再点或按 Esc 取消,读屏会播报。
15
16
  * - v-model 是选中日期,v-model:month 是显示的月份(`YYYY-MM`);翻月后按 ysMonthRange(month) 取这一屏的日期信息。
16
17
  * - 键盘:方向键移动一天或一周,PageUp / PageDown 翻月,Home / End 到本周一 / 周日,Enter 或空格选中;跨月自动翻页。
17
- * - 事件条(events)每格最多 maxEvents 条,其余收成「+N」(触发 more);要完全自定义格子内容用 #day 插槽。
18
- * - 交易所额外休市(国务院安排上班、交易所休市,如 2024-02-09 除夕):交易日视图按休市显示,两种视图都写「交易所休市」。
19
- * - night:交易日视图标出期货夜盘——当晚有夜盘的交易日在标签旁写小「夜」,节前等没有夜盘的交易日写「无夜盘」。
18
+ * - 事件条(events)每格最多 maxEvents 条(有日期信息时默认 2 条,没有时 3 条),其余收成「+N」(触发 more);
19
+ * 要完全自定义格子内容用 #day 插槽。
20
+ * - 紧凑格子(size="small" 或手机):只有日期、底色、「班」「休」角标、日期下方蓝色短横(开市)和短横后的靛紫圆点(夜盘),
21
+ * 事件圆点在左上角。
20
22
  * - years:各年数据来源与核对状态(服务端 CalendarService.year_states()),传了就在顶部写这一屏所在年份的来源,
21
23
  * 如「2026 年:Auth 下发 · 已与交易所核对」,悬停看各数据源的核对结果。
24
+ * - mark、trading、night 是以前分视图时的参数,现在只有一种样式,传了也不起作用。
22
25
  */
23
26
  import { computed, nextTick, ref, watch } from "vue";
24
27
  import { useYsMobile } from "../viewport";
25
28
  import {
26
29
  YS_DAY_KIND_LABELS,
30
+ YS_NIGHT_SESSION_START,
27
31
  YS_TRADING_TAG_LABELS,
28
32
  YS_WEEKDAY_LABELS,
29
33
  ysAddDays,
@@ -33,6 +37,7 @@ import {
33
37
  ysMonthOf,
34
38
  ysMonthSummary,
35
39
  ysShiftMonth,
40
+ ysShortDateTitle,
36
41
  ysToday,
37
42
  ysTradingMarks,
38
43
  ysWeekday,
@@ -50,7 +55,10 @@ export interface YsCalendarEvent {
50
55
  tone?: "primary" | "success" | "warning" | "danger" | "info";
51
56
  }
52
57
 
53
- /** 格子状态:交易日视图 trading / closed,工作日视图 workday / adjusted / weekend / holiday。 */
58
+ /**
59
+ * 格子状态:交易日 trading,其余按工作类型 workday(上班但交易所休市)/ adjusted / weekend / holiday。
60
+ * closed 是以前交易日视图的休市,现在不再出现,只为兼容保留在类型里。
61
+ */
54
62
  export type YsCalendarStatus =
55
63
  | "trading"
56
64
  | "closed"
@@ -58,16 +66,24 @@ export type YsCalendarStatus =
58
66
  | "adjusted"
59
67
  | "weekend"
60
68
  | "holiday";
61
- /** 各状态标签上的文字。 */
62
- export type YsCalendarLabels = Record<YsCalendarStatus, string>;
69
+ /** 标签上的文字:各状态加夜盘 night。 */
70
+ export type YsCalendarLabels = Record<YsCalendarStatus | "night", string>;
71
+ /** 图例能突出的几类:上班(含补班)、补班、放假、开市、夜盘。 */
72
+ export type YsCalendarLegendKey =
73
+ | "workday"
74
+ | "adjusted"
75
+ | "holiday"
76
+ | "trading"
77
+ | "night";
63
78
 
64
79
  const DEFAULT_LABELS: YsCalendarLabels = {
65
- trading: "交易日",
80
+ trading: "开市",
66
81
  closed: "休市",
67
- workday: "工作日",
68
- adjusted: "法定补班",
82
+ workday: "上班",
83
+ adjusted: "补班",
69
84
  weekend: "休息",
70
85
  holiday: "放假",
86
+ night: "夜盘",
71
87
  };
72
88
 
73
89
  const props = withDefaults(
@@ -79,24 +95,25 @@ const props = withDefaults(
79
95
  today?: string;
80
96
  loading?: boolean;
81
97
  size?: "default" | "small";
82
- /** 视图:none 默认(不标状态)、work 工作日、trading 交易日。 */
98
+ /** @deprecated 以前的视图切换,现在只有一种综合样式,传了不起作用。 */
83
99
  mark?: "work" | "trading" | "none";
84
- /** 旧写法,等于 mark="trading"。 */
100
+ /** @deprecated 以前等于 mark="trading",现在不起作用。 */
85
101
  trading?: boolean;
86
- /** 改标签文字,只写要改的几项,如 { adjusted: "调休上班" }。 */
102
+ /** 改标签文字,只写要改的几项,如 { adjusted: "调休" }。 */
87
103
  labels?: Partial<YsCalendarLabels>;
88
- /** 每格右上角显示状态标签(迷你模式不显示,只留底色)。 */
104
+ /** 每格右上角显示上班、开市等标签(底色和夜盘照常)。 */
89
105
  showLabel?: boolean;
90
- /** 交易日视图在标签旁写本月第几个交易日(默认不写,选中日详情里写)。 */
106
+ /** 左下角写本月第几个交易日(默认不写,选中日详情里写)。 */
91
107
  showOrdinal?: boolean;
92
- /** 顶部显示本月统计(工作日视图:工作日、法定补班、放假;交易日视图:交易日、休市)。 */
108
+ /** 顶部显示本月统计(开市、上班(含补班)、放假、交易所休市、夜盘)。 */
93
109
  summary?: boolean;
110
+ /** 每格最多几条事件;不传时有日期信息 2 条、没有 3 条。 */
94
111
  maxEvents?: number;
95
112
  /** 不能选的日期(如非交易日):变淡、点了不选中。 */
96
113
  disabledDate?: (date: string, info?: YsCalendarDay) => boolean;
97
114
  /** 显示底部图例;默认有日期信息时显示。 */
98
115
  legend?: boolean | null;
99
- /** 交易日视图标出期货夜盘(有夜盘写「夜」,没有写「无夜盘」)。 */
116
+ /** @deprecated 夜盘现在有数据就标,传了不起作用。 */
100
117
  night?: boolean;
101
118
  /** 各年数据来源与核对状态;传了就在顶部写这一屏所在年份的来源。 */
102
119
  years?: readonly YsCalendarYearInfo[];
@@ -115,7 +132,7 @@ const props = withDefaults(
115
132
  showLabel: true,
116
133
  showOrdinal: false,
117
134
  summary: false,
118
- maxEvents: 3,
135
+ maxEvents: undefined,
119
136
  disabledDate: undefined,
120
137
  legend: null,
121
138
  night: false,
@@ -161,22 +178,19 @@ const eventMap = computed(() => {
161
178
  });
162
179
  const small = computed(() => props.size === "small");
163
180
  /**
164
- * 格子紧凑:迷你模式,或者手机(≤767px,每格只有 50px 左右宽,放不下状态标签和事件条)。
165
- * 紧凑时格子里只有日期、底色、休 / 班角标和事件圆点;手机上月份统计、数据来源、图例照常显示,详情看旁边的 YsCalendarDayCard。
181
+ * 格子紧凑:迷你模式,或者手机(≤767px,每格只有 50px 左右宽,放不下文字标签和事件条)。
182
+ * 紧凑时格子里只有日期、底色、休 / 班角标、开市短横、夜盘圆点和事件圆点;详情看旁边的 YsCalendarDayCard。
166
183
  */
167
184
  const mobile = useYsMobile();
168
185
  const compact = computed(() => small.value || mobile.value);
169
- const view = computed(() => props.mark ?? (props.trading ? "trading" : "none"));
170
- const tradingView = computed(() => view.value === "trading");
171
186
  const labelText = computed<YsCalendarLabels>(() => ({
172
187
  ...DEFAULT_LABELS,
173
188
  ...props.labels,
174
189
  }));
175
- const marks = computed(() =>
176
- tradingView.value
177
- ? ysTradingMarks(props.days)
178
- : new Map<string, YsTradingMark>(),
190
+ const eventLimit = computed(
191
+ () => props.maxEvents ?? (props.days.length ? 2 : 3),
179
192
  );
193
+ const marks = computed(() => ysTradingMarks(props.days));
180
194
 
181
195
  /** 这一屏里还没有放假安排的年份。 */
182
196
  const missingYears = computed(() => {
@@ -216,25 +230,25 @@ const todayVisible = computed(() =>
216
230
  cells.value.some((cell) => cell.date === todayText.value),
217
231
  );
218
232
 
219
- /** 顶部统计:拆成「名称 + 数字」几段,数字加粗。月份信息不全时不显示。 */
233
+ /** 顶部统计:「开市 21 · 上班 22(含补班 1)· 放假 3 · 交易所休市 1 · 夜盘 17」,为 0 的项省略。月份信息不全时不显示。 */
220
234
  const summaryParts = computed(() => {
221
- if (!props.summary || small.value || view.value === "none") return [];
235
+ if (!props.summary || small.value || !props.days.length) return [];
222
236
  const value = ysMonthSummary(props.days, shownMonth.value);
223
237
  if (!value.complete) return [];
224
238
  const labels = labelText.value;
225
- if (tradingView.value)
226
- return [
227
- { label: labels.trading, value: value.trading },
228
- { label: labels.closed, value: value.closed },
229
- ];
230
- // 和图例一致:工作日不含法定补班,法定补班单列
231
- const parts = [
232
- { label: labels.workday, value: value.workdays - value.adjusted },
239
+ const parts: { label: string; value: number; note?: string }[] = [
240
+ { label: labels.trading, value: value.trading },
241
+ {
242
+ label: labels.workday,
243
+ value: value.workdays,
244
+ note: value.adjusted ? `含${labels.adjusted} ${value.adjusted}` : "",
245
+ },
233
246
  ];
234
- if (value.adjusted)
235
- parts.push({ label: labels.adjusted, value: value.adjusted });
236
247
  if (value.holidays)
237
248
  parts.push({ label: labels.holiday, value: value.holidays });
249
+ if (value.marketClosed)
250
+ parts.push({ label: "交易所休市", value: value.marketClosed });
251
+ if (value.night) parts.push({ label: labels.night, value: value.night });
238
252
  return parts;
239
253
  });
240
254
 
@@ -251,62 +265,70 @@ function info(date: string): YsCalendarDay | undefined {
251
265
  function eventsOf(date: string): YsCalendarEvent[] {
252
266
  return eventMap.value.get(date) ?? [];
253
267
  }
254
- function covered(date: string): boolean {
268
+ /** 有日期信息、这一年有放假安排时才是可信的那天信息。 */
269
+ function known(date: string): YsCalendarDay | undefined {
255
270
  const item = info(date);
256
- return Boolean(item) && item?.covered !== false;
271
+ return item && item.covered !== false ? item : undefined;
257
272
  }
258
- /** 这一天的状态;没有日期信息、这一年没有放假安排或 mark="none" 时为空。 */
273
+ /** 这一天的状态:交易日 trading,其余按工作类型;没有日期信息或这一年没有放假安排时为空。 */
259
274
  function status(date: string): YsCalendarStatus | "" {
260
- if (view.value === "none" || !covered(date)) return "";
261
- const item = info(date);
275
+ const item = known(date);
262
276
  if (!item) return "";
263
- if (tradingView.value) return item.trading ? "trading" : "closed";
264
- return item.kind;
277
+ return item.trading ? "trading" : item.kind;
265
278
  }
266
- /** 上月、下月的格子只留淡底色和日期,标签、序号、节日名只在本月写。 */
279
+ /** 上月、下月的格子只留淡底色和日期,标签、序号、节日名、夜盘只在本月写。 */
267
280
  function inShownMonth(date: string): boolean {
268
281
  return date.startsWith(shownMonth.value);
269
282
  }
270
- function statusLabel(date: string): string {
271
- if (!inShownMonth(date)) return "";
272
- const value = status(date);
273
- return value ? labelText.value[value] : "";
274
- }
275
- /** 迷你模式工作日视图在数字右上角挂「休」「班」小角标。 */
283
+ /** 右上角标签:先上班类(上班 / 补班 / 放假,周末不写),再开市。 */
284
+ function cellLabels(
285
+ date: string,
286
+ ): { key: YsCalendarLegendKey; text: string }[] {
287
+ const item = known(date);
288
+ if (!item || !inShownMonth(date)) return [];
289
+ const labels = labelText.value;
290
+ const list: { key: YsCalendarLegendKey; text: string }[] = [];
291
+ if (item.kind === "adjusted")
292
+ list.push({ key: "adjusted", text: labels.adjusted });
293
+ else if (item.kind === "holiday")
294
+ list.push({ key: "holiday", text: labels.holiday });
295
+ else if (item.kind === "workday")
296
+ list.push({ key: "workday", text: labels.workday });
297
+ if (item.trading) list.push({ key: "trading", text: labels.trading });
298
+ return list;
299
+ }
300
+ /** 迷你模式和手机在数字右上角挂「休」「班」小角标。 */
276
301
  function badge(date: string): "休" | "班" | "" {
277
302
  if (!inShownMonth(date)) return "";
278
- const value = status(date);
279
- return value === "holiday" ? "休" : value === "adjusted" ? "班" : "";
303
+ const kind = known(date)?.kind;
304
+ return kind === "holiday" ? "休" : kind === "adjusted" ? "班" : "";
280
305
  }
281
306
  function isWeekendCell(cell: YsMonthCell): boolean {
282
- const value = status(cell.date);
283
- if (value) return value === "weekend" || value === "holiday";
307
+ const item = known(cell.date);
308
+ if (item) return item.kind === "weekend" || item.kind === "holiday";
284
309
  return cell.weekday >= 5;
285
310
  }
286
- /** 状态标签下面那一行:节日名;交易日视图休市日写「国庆节 · 休市」,法定补班写「国庆节调休」,
287
- * 交易所额外休市写「交易所休市」,夜盘视图下没有夜盘的交易日写「无夜盘」。 */
311
+ /** 标签下面那一行:交易所额外休市写「交易所休市」,法定补班写「国庆节调休」,放假写节日名。 */
288
312
  function subline(date: string): string {
289
313
  if (!inShownMonth(date)) return "";
290
- const value = status(date);
291
- const item = info(date);
292
- const name = item?.name ?? "";
293
- if (value && item?.market_closed) return "交易所休市";
294
- if (value === "trading" && props.night && item?.night_session === false)
295
- return "无夜盘";
296
- if (!value || !name) return "";
297
- if (value === "closed") return `${name} · ${labelText.value.closed}`;
298
- if (value === "adjusted") return `${name}调休`;
299
- return name;
300
- }
301
- /** 夜盘视图下当晚有夜盘的交易日。 */
314
+ const item = known(date);
315
+ if (!item) return "";
316
+ if (item.market_closed) return "交易所休市";
317
+ if (!item.name) return "";
318
+ if (item.kind === "adjusted") return `${item.name}调休`;
319
+ if (item.kind === "holiday") return item.name;
320
+ return "";
321
+ }
322
+ /** 当晚有期货夜盘的交易日(没有、未知都不标)。 */
323
+ function nightOn(date: string): boolean {
324
+ const item = known(date);
325
+ return Boolean(item?.trading && item.night_session === true);
326
+ }
302
327
  function hasNight(date: string): boolean {
303
- return (
304
- props.night &&
305
- tradingView.value &&
306
- inShownMonth(date) &&
307
- status(date) === "trading" &&
308
- info(date)?.night_session === true
309
- );
328
+ return inShownMonth(date) && nightOn(date);
329
+ }
330
+ function isOpen(date: string): boolean {
331
+ return inShownMonth(date) && Boolean(known(date)?.trading);
310
332
  }
311
333
  function ordinalOf(date: string): number | undefined {
312
334
  return props.showOrdinal && inShownMonth(date)
@@ -319,35 +341,45 @@ function markOf(date: string): YsTradingMark | undefined {
319
341
  function disabled(date: string): boolean {
320
342
  return Boolean(props.disabledDate?.(date, info(date)));
321
343
  }
344
+ /** 读屏念的整句话:日期,上班类,开市或休市,当晚夜盘,关键交易日,今天,事项。 */
322
345
  function ariaLabel(cell: YsMonthCell): string {
323
346
  const item = info(cell.date);
324
347
  const parts = [ysDateTitle(cell.date)];
325
348
  if (item?.covered === false) parts.push("放假安排还没有");
326
- else if (item && view.value !== "none") {
327
- parts.push(
328
- item.name
329
- ? `${YS_DAY_KIND_LABELS[item.kind]} ${item.name}`
330
- : YS_DAY_KIND_LABELS[item.kind],
331
- );
332
- if (item.market_closed) parts.push(`交易所休市(${item.market_closed})`);
333
- if (tradingView.value) {
334
- const mark = markOf(cell.date);
349
+ else if (item) {
350
+ const name = item.name ?? "";
351
+ if (item.kind === "workday") parts.push("上班");
352
+ else if (item.kind === "adjusted")
353
+ parts.push(
354
+ name
355
+ ? `${YS_DAY_KIND_LABELS.adjusted}(${name}调休)`
356
+ : YS_DAY_KIND_LABELS.adjusted,
357
+ );
358
+ else if (item.kind === "holiday")
359
+ parts.push(name ? `放假 ${name}` : "放假");
360
+ else parts.push(YS_DAY_KIND_LABELS.weekend);
361
+ const mark = markOf(cell.date);
362
+ if (item.trading)
363
+ parts.push(
364
+ mark?.ordinal ? `开市,本月第 ${mark.ordinal} 个交易日` : "开市",
365
+ );
366
+ else if (item.market_closed)
367
+ parts.push(`交易所休市(${item.market_closed})`);
368
+ else parts.push("休市");
369
+ if (item.trading && item.night_session === true)
335
370
  parts.push(
336
- item.trading
337
- ? mark?.ordinal
338
- ? `本月第 ${mark.ordinal} 个交易日`
339
- : "交易日"
340
- : "休市",
371
+ item.night_trading_day
372
+ ? `当晚有夜盘,计入 ${ysShortDateTitle(item.night_trading_day)} 交易日`
373
+ : "当晚有夜盘",
341
374
  );
342
- if (props.night && item.trading && item.night_session != null)
343
- parts.push(
344
- item.night_session
345
- ? `当晚有夜盘,归属 ${item.night_trading_day ?? ""}`
346
- : "当晚没有夜盘",
347
- );
348
- for (const tag of mark?.tags ?? [])
349
- parts.push(YS_TRADING_TAG_LABELS[tag].full);
350
- }
375
+ else if (
376
+ item.trading &&
377
+ item.night_session === false &&
378
+ cell.date >= YS_NIGHT_SESSION_START
379
+ )
380
+ parts.push("当晚没有夜盘");
381
+ for (const tag of mark?.tags ?? [])
382
+ parts.push(YS_TRADING_TAG_LABELS[tag].full);
351
383
  }
352
384
  if (cell.date === todayText.value) parts.push("今天");
353
385
  const count = eventsOf(cell.date).length;
@@ -356,24 +388,44 @@ function ariaLabel(cell: YsMonthCell): string {
356
388
  return parts.join(",");
357
389
  }
358
390
 
359
- // ---------- 图例:悬停或点一项,只突出这一类 ----------
360
- const legendItems = computed<{ key: YsCalendarStatus; text: string }[]>(() => {
361
- if (tradingView.value)
362
- return [
363
- { key: "trading", text: props.showOrdinal ? "旁边是本月第几个" : "" },
364
- {
365
- key: "closed",
366
- text: `周末、放假、交易所休市和${labelText.value.adjusted}的周末`,
367
- },
368
- ];
369
- if (view.value === "work")
370
- return [
371
- { key: "workday", text: "" },
372
- { key: "adjusted", text: "调休上班的周末" },
373
- { key: "weekend", text: "" },
374
- { key: "holiday", text: "法定节假日" },
375
- ];
376
- return [];
391
+ // ---------- 图例:按条件突出一类 ----------
392
+ /** 这一天是否属于图例的某一类。 */
393
+ function matches(date: string, key: YsCalendarLegendKey): boolean {
394
+ const item = known(date);
395
+ if (!item) return false;
396
+ if (key === "workday") return Boolean(item.workday);
397
+ if (key === "adjusted") return item.kind === "adjusted";
398
+ if (key === "holiday") return item.kind === "holiday";
399
+ if (key === "trading") return Boolean(item.trading);
400
+ return nightOn(date);
401
+ }
402
+ function legendCount(key: YsCalendarLegendKey): number {
403
+ return cells.value.filter((cell) => cell.inMonth && matches(cell.date, key))
404
+ .length;
405
+ }
406
+ const LEGEND_NOTES: Record<YsCalendarLegendKey, string> = {
407
+ workday: "要上班的日子,含补班",
408
+ adjusted: "调休上班的周末,交易所休市",
409
+ holiday: "法定节假日",
410
+ trading: "交易所开市",
411
+ night: "当晚 21:00 起有期货夜盘",
412
+ };
413
+ /** 上班、开市一直列出;补班、放假、夜盘本月有才列。 */
414
+ const legendItems = computed(() => {
415
+ if (!props.days.length) return [];
416
+ const keys: YsCalendarLegendKey[] = [
417
+ "workday",
418
+ "adjusted",
419
+ "holiday",
420
+ "trading",
421
+ "night",
422
+ ];
423
+ return keys
424
+ .map((key) => ({ key, count: legendCount(key) }))
425
+ .filter(
426
+ (item) =>
427
+ item.key === "workday" || item.key === "trading" || item.count > 0,
428
+ );
377
429
  });
378
430
  const showLegend = computed(
379
431
  () =>
@@ -381,19 +433,38 @@ const showLegend = computed(
381
433
  (props.legend ?? props.days.length > 0) &&
382
434
  (legendItems.value.length > 0 || todayVisible.value),
383
435
  );
384
- const legendHover = ref<YsCalendarStatus | "">("");
385
- const legendPinned = ref<YsCalendarStatus | "">("");
386
- const focusStatus = computed(() => legendHover.value || legendPinned.value);
387
- watch(view, () => {
388
- legendHover.value = "";
389
- legendPinned.value = "";
390
- });
391
- function togglePinned(key: YsCalendarStatus) {
436
+ const legendHover = ref<YsCalendarLegendKey | "">("");
437
+ const legendPinned = ref<YsCalendarLegendKey | "">("");
438
+ const focusKey = computed(() => legendHover.value || legendPinned.value);
439
+ /** 固定、取消时给读屏的播报。 */
440
+ const legendAnnounce = ref("");
441
+ function togglePinned(key: YsCalendarLegendKey) {
392
442
  legendPinned.value = legendPinned.value === key ? "" : key;
443
+ legendAnnounce.value = legendPinned.value
444
+ ? `已只突出${labelText.value[key]},本月 ${legendCount(key)} 天`
445
+ : "已取消突出";
393
446
  }
394
- function legendCount(key: YsCalendarStatus): number {
395
- return cells.value.filter((cell) => cell.inMonth && status(cell.date) === key)
396
- .length;
447
+ function clearLegend(announce = true) {
448
+ if (!legendPinned.value && !legendHover.value) return;
449
+ legendHover.value = "";
450
+ if (legendPinned.value) {
451
+ legendPinned.value = "";
452
+ if (announce) legendAnnounce.value = "已取消突出";
453
+ }
454
+ }
455
+ /** 翻月或图例列表变化时,固定的那一项若已不在列表里,自动清掉,避免整屏变淡。 */
456
+ watch(legendItems, (items) => {
457
+ if (legendPinned.value && !items.some((i) => i.key === legendPinned.value)) {
458
+ legendHover.value = "";
459
+ legendPinned.value = "";
460
+ }
461
+ });
462
+ /** 图例隐藏时(迷你模式、legend=false)同样清掉固定状态。 */
463
+ watch(showLegend, (visible) => {
464
+ if (!visible) clearLegend(false);
465
+ });
466
+ function dimmed(date: string): boolean {
467
+ return Boolean(focusKey.value) && !matches(date, focusKey.value as YsCalendarLegendKey);
397
468
  }
398
469
 
399
470
  // ---------- 选择与键盘 ----------
@@ -443,6 +514,10 @@ function onKeydown(event: KeyboardEvent) {
443
514
  PageUp: () => shiftKeepDay(current, -1),
444
515
  PageDown: () => shiftKeepDay(current, 1),
445
516
  };
517
+ if (event.key === "Escape") {
518
+ clearLegend();
519
+ return;
520
+ }
446
521
  if (event.key === "Enter" || event.key === " ") {
447
522
  event.preventDefault();
448
523
  select(current);
@@ -476,8 +551,7 @@ function goToday() {
476
551
  'is-small': small,
477
552
  'is-compact': compact,
478
553
  'is-mobile': mobile,
479
- 'is-trading-view': tradingView,
480
- 'is-focusing': Boolean(focusStatus),
554
+ 'is-focusing': Boolean(focusKey),
481
555
  }"
482
556
  >
483
557
  <header class="ys-calendar__head">
@@ -524,7 +598,10 @@ function goToday() {
524
598
  :key="part.label"
525
599
  class="ys-calendar__summary-item"
526
600
  ><span>{{ part.label }}</span
527
- ><strong>{{ part.value }}</strong></span
601
+ ><strong>{{ part.value }}</strong
602
+ ><span v-if="part.note" class="ys-calendar__summary-note"
603
+ >({{ part.note }})</span
604
+ ></span
528
605
  >
529
606
  </div>
530
607
  <span
@@ -584,7 +661,6 @@ function goToday() {
584
661
  :aria-selected="cell.date === modelValue"
585
662
  :aria-disabled="disabled(cell.date) || undefined"
586
663
  :aria-label="ariaLabel(cell)"
587
- :title="ariaLabel(cell)"
588
664
  :class="[
589
665
  status(cell.date) ? `is-${status(cell.date)}` : '',
590
666
  {
@@ -594,8 +670,7 @@ function goToday() {
594
670
  'is-weekend-day': isWeekendCell(cell),
595
671
  'is-uncovered': info(cell.date)?.covered === false,
596
672
  'is-disabled': disabled(cell.date),
597
- 'is-dimmed':
598
- Boolean(focusStatus) && status(cell.date) !== focusStatus,
673
+ 'is-dimmed': dimmed(cell.date),
599
674
  },
600
675
  ]"
601
676
  @click="select(cell.date)"
@@ -617,44 +692,35 @@ function goToday() {
617
692
  v-if="compact && badge(cell.date)"
618
693
  class="ys-calendar__badge"
619
694
  :class="badge(cell.date) === '休' ? 'is-off' : 'is-work'"
695
+ aria-hidden="true"
620
696
  >{{ badge(cell.date) }}</span
621
697
  >
622
698
  <span
623
- v-else-if="
624
- !compact &&
625
- (ordinalOf(cell.date) ||
626
- hasNight(cell.date) ||
627
- (showLabel && statusLabel(cell.date)))
628
- "
699
+ v-else-if="!compact && showLabel && cellLabels(cell.date).length"
629
700
  class="ys-calendar__status"
701
+ aria-hidden="true"
630
702
  >
631
703
  <span
632
- v-if="ordinalOf(cell.date)"
633
- class="ys-calendar__ordinal"
634
- aria-hidden="true"
635
- >第 {{ ordinalOf(cell.date) }} 个</span
636
- >
637
- <span
638
- v-if="hasNight(cell.date)"
639
- class="ys-calendar__night"
640
- aria-hidden="true"
641
- >夜</span
642
- >
643
- <span
644
- v-if="showLabel && statusLabel(cell.date)"
704
+ v-for="label in cellLabels(cell.date)"
705
+ :key="label.key"
645
706
  class="ys-calendar__label"
646
- aria-hidden="true"
647
- >{{ statusLabel(cell.date) }}</span
707
+ :class="`is-${label.key}`"
708
+ >{{ label.text }}</span
648
709
  >
649
710
  </span>
650
711
  </div>
651
712
  <template v-if="!compact">
652
- <div v-if="subline(cell.date)" class="ys-calendar__name">
713
+ <div
714
+ v-if="subline(cell.date)"
715
+ class="ys-calendar__name"
716
+ :class="{ 'is-market-closed': info(cell.date)?.market_closed }"
717
+ aria-hidden="true"
718
+ >
653
719
  {{ subline(cell.date) }}
654
720
  </div>
655
721
  <ul v-if="eventsOf(cell.date).length" class="ys-calendar__events">
656
722
  <li
657
- v-for="item in eventsOf(cell.date).slice(0, maxEvents)"
723
+ v-for="item in eventsOf(cell.date).slice(0, eventLimit)"
658
724
  :key="item.id ?? item.title"
659
725
  class="ys-calendar__event"
660
726
  :class="`is-${item.tone ?? 'primary'}`"
@@ -662,22 +728,44 @@ function goToday() {
662
728
  >
663
729
  {{ item.title }}
664
730
  </li>
665
- <li v-if="eventsOf(cell.date).length > maxEvents">
731
+ <li v-if="eventsOf(cell.date).length > eventLimit">
666
732
  <button
667
733
  type="button"
668
734
  class="ys-calendar__more"
669
735
  tabindex="-1"
670
736
  @click.stop="emit('more', cell.date)"
671
- v-text="`+${eventsOf(cell.date).length - maxEvents}`"
737
+ v-text="`+${eventsOf(cell.date).length - eventLimit}`"
672
738
  />
673
739
  </li>
674
740
  </ul>
741
+ <div
742
+ v-if="ordinalOf(cell.date) || hasNight(cell.date)"
743
+ class="ys-calendar__foot"
744
+ aria-hidden="true"
745
+ >
746
+ <span v-if="ordinalOf(cell.date)" class="ys-calendar__ordinal"
747
+ >第 {{ ordinalOf(cell.date) }} 个</span
748
+ >
749
+ <span v-if="hasNight(cell.date)" class="ys-calendar__night">{{
750
+ labelText.night
751
+ }}</span>
752
+ </div>
753
+ </template>
754
+ <template v-else>
755
+ <span
756
+ v-if="isOpen(cell.date)"
757
+ class="ys-calendar__marks"
758
+ aria-hidden="true"
759
+ ><i class="ys-calendar__open-bar" /><i
760
+ v-if="hasNight(cell.date)"
761
+ class="ys-calendar__night-dot"
762
+ /></span>
763
+ <span
764
+ v-if="eventsOf(cell.date).length"
765
+ class="ys-calendar__dot"
766
+ aria-hidden="true"
767
+ />
675
768
  </template>
676
- <span
677
- v-else-if="eventsOf(cell.date).length"
678
- class="ys-calendar__dot"
679
- aria-hidden="true"
680
- />
681
769
  </slot>
682
770
  </div>
683
771
  </div>
@@ -691,33 +779,36 @@ function goToday() {
691
779
  class="ys-calendar__legend-item"
692
780
  :class="[`is-${item.key}`, { 'is-active': legendPinned === item.key }]"
693
781
  :aria-pressed="legendPinned === item.key"
694
- :title="`只突出${labelText[item.key]},再点一次取消`"
782
+ :title="`${LEGEND_NOTES[item.key]};点一下只突出这一类,再点或按 Esc 取消`"
695
783
  @mouseenter="legendHover = item.key"
696
784
  @mouseleave="legendHover = ''"
697
785
  @focus="legendHover = item.key"
698
786
  @blur="legendHover = ''"
787
+ @keydown.esc="() => clearLegend()"
699
788
  @click="togglePinned(item.key)"
700
789
  >
701
- <i class="ys-calendar__swatch">{{ labelText[item.key] }}</i>
702
- <strong>{{ legendCount(item.key) }}</strong>
703
- <span v-if="item.text" class="ys-calendar__legend-note">{{
704
- item.text
705
- }}</span>
790
+ <i
791
+ class="ys-calendar__swatch"
792
+ :class="{ 'ys-calendar__night': item.key === 'night' }"
793
+ >{{ labelText[item.key] }}</i
794
+ >
795
+ <strong>{{ item.count }}</strong>
706
796
  </button>
707
- <span v-if="night && tradingView" class="ys-calendar__legend-night"
708
- ><i class="ys-calendar__night">夜</i>当晚有期货夜盘</span
709
- >
710
797
  <span v-if="todayVisible" class="ys-calendar__legend-today">今天</span>
798
+ <span class="ys-calendar__sr-only" aria-live="polite">{{
799
+ legendAnnounce
800
+ }}</span>
711
801
  </footer>
712
802
  </div>
713
803
  </template>
714
804
 
715
805
  <style scoped>
716
806
  .ys-calendar {
717
- /* 每种状态一个色调:交易日、工作日和法定补班绿,放假橙,休息、休市灰 */
718
- --cal-trading: var(--ys-color-success);
807
+ /* 色调各管一件事:上班(含补班)绿,放假橙,开市主色蓝,夜盘靛紫,休息、休市灰 */
808
+ --cal-trading: var(--ys-color-primary);
719
809
  --cal-workday: var(--ys-color-success);
720
810
  --cal-holiday: var(--ys-color-warning);
811
+ --cal-night: #5b4bd6;
721
812
  --cal-rest: var(--ys-color-text-3);
722
813
  /* 底色:不支持相对颜色的浏览器用混色兜底 */
723
814
  --cal-open-bg: color-mix(
@@ -745,6 +836,9 @@ function goToday() {
745
836
  gap: 8px;
746
837
  min-width: 0;
747
838
  }
839
+ html[data-theme="dark"] .ys-calendar {
840
+ --cal-night: #a597ff;
841
+ }
748
842
  /* 支持相对颜色时,底色固定亮度和饱和度:和休息日(白底/深底)一眼分得开的绿和橙,饱和度仍克制、不刺眼 */
749
843
  @supports (color: oklch(from red l c h)) {
750
844
  .ys-calendar {
@@ -777,12 +871,8 @@ function goToday() {
777
871
  font-size: 18px;
778
872
  }
779
873
  .ys-calendar__nav :deep(.el-date-editor.ys-calendar__month) {
780
- width: 128px;
781
- }
782
- .ys-calendar.is-small
783
- .ys-calendar__nav
784
- :deep(.el-date-editor.ys-calendar__month) {
785
- width: 112px;
874
+ width: 144px;
875
+ min-width: 128px;
786
876
  }
787
877
  .ys-calendar__summary {
788
878
  display: flex;
@@ -826,27 +916,22 @@ function goToday() {
826
916
  );
827
917
  background: color-mix(in srgb, var(--ys-color-warning) 12%, transparent);
828
918
  }
829
- /* 夜盘角标:小号描边「夜」,不抢交易日标签 */
919
+ /* 夜盘:靛紫实心小标签,像夜色;在格子右下角,是格子里最后一个元素 */
830
920
  .ys-calendar__night {
831
921
  flex: none;
832
- padding: 0 3px;
833
- border: 1px solid color-mix(in srgb, var(--ys-color-primary) 45%, transparent);
922
+ padding: 0 4px;
923
+ border: 1px solid var(--cal-night);
834
924
  border-radius: var(--ys-radius-s);
835
- color: color-mix(
836
- in srgb,
837
- var(--ys-color-primary) 85%,
838
- var(--ys-color-text-1)
839
- );
925
+ color: var(--ys-color-on-solid);
926
+ background: var(--cal-night);
840
927
  font-size: 10px;
841
928
  font-style: normal;
842
929
  font-weight: 600;
843
930
  line-height: 14px;
931
+ white-space: nowrap;
844
932
  }
845
- .ys-calendar__legend-night {
846
- display: inline-flex;
847
- gap: 5px;
848
- align-items: center;
849
- margin-left: 6px;
933
+ .ys-calendar__summary-note {
934
+ color: var(--ys-color-text-3);
850
935
  }
851
936
  .ys-calendar__extra {
852
937
  display: flex;
@@ -982,7 +1067,7 @@ function goToday() {
982
1067
  .ys-calendar__top {
983
1068
  display: flex;
984
1069
  gap: 4px;
985
- align-items: center;
1070
+ align-items: flex-start;
986
1071
  justify-content: space-between;
987
1072
  min-width: 0;
988
1073
  }
@@ -1013,12 +1098,15 @@ function goToday() {
1013
1098
  color: var(--ys-color-on-solid);
1014
1099
  background: var(--ys-color-primary);
1015
1100
  }
1101
+ /* 右上角标签组:上班类在前、开市在后;一行放不下时开市退到下一行,仍靠右,不截断 */
1016
1102
  .ys-calendar__status {
1017
- display: inline-flex;
1018
- gap: 4px;
1019
- align-items: center;
1103
+ display: flex;
1104
+ flex: 1 1 auto;
1105
+ flex-wrap: wrap;
1106
+ gap: 3px;
1107
+ justify-content: flex-end;
1020
1108
  min-width: 0;
1021
- overflow: hidden;
1109
+ margin-top: 3px;
1022
1110
  }
1023
1111
  .ys-calendar__ordinal {
1024
1112
  overflow: hidden;
@@ -1027,11 +1115,11 @@ function goToday() {
1027
1115
  font-variant-numeric: tabular-nums;
1028
1116
  white-space: nowrap;
1029
1117
  }
1030
- /* 状态标签:白底同色调描边深字,在有底色的格子上也清楚;法定补班是实心,最醒目 */
1118
+ /* 标签:白底同色调描边深字,在有底色的格子上也清楚;补班实心最醒目,开市蓝色浅底,和上班的描边一眼分开 */
1031
1119
  .ys-calendar__label,
1032
1120
  .ys-calendar__swatch {
1033
1121
  flex: none;
1034
- padding: 0 5px;
1122
+ padding: 0 4px;
1035
1123
  border: 1px solid color-mix(in srgb, var(--tone) 60%, transparent);
1036
1124
  border-radius: var(--ys-radius-s);
1037
1125
  color: color-mix(in srgb, var(--tone) 88%, var(--ys-color-text-1));
@@ -1042,31 +1130,31 @@ function goToday() {
1042
1130
  line-height: 16px;
1043
1131
  white-space: nowrap;
1044
1132
  }
1045
- .ys-calendar__cell.is-closed .ys-calendar__label,
1046
- .ys-calendar__cell.is-weekend .ys-calendar__label,
1047
- .ys-calendar__legend-item.is-closed .ys-calendar__swatch,
1048
- .ys-calendar__legend-item.is-weekend .ys-calendar__swatch {
1049
- border-color: transparent;
1050
- color: var(--ys-color-text-2);
1051
- background: color-mix(in srgb, var(--cal-rest) 14%, transparent);
1133
+ .ys-calendar__label.is-workday,
1134
+ .ys-calendar__legend-item.is-workday .ys-calendar__swatch {
1135
+ --tone: var(--cal-workday);
1052
1136
  }
1053
- /* 「交易日」标签用主色蓝,格子仍是浅绿底 */
1054
- .ys-calendar__cell.is-trading .ys-calendar__label,
1055
- .ys-calendar__legend-item.is-trading .ys-calendar__swatch {
1056
- color: color-mix(
1057
- in srgb,
1058
- var(--ys-color-primary) 85%,
1059
- var(--ys-color-text-1)
1060
- );
1061
- border-color: color-mix(in srgb, var(--ys-color-primary) 60%, transparent);
1062
- background: var(--ys-color-bg-elevated);
1137
+ .ys-calendar__label.is-holiday,
1138
+ .ys-calendar__legend-item.is-holiday .ys-calendar__swatch {
1139
+ --tone: var(--cal-holiday);
1063
1140
  }
1064
- .ys-calendar__cell.is-adjusted .ys-calendar__label,
1141
+ .ys-calendar__label.is-adjusted,
1065
1142
  .ys-calendar__legend-item.is-adjusted .ys-calendar__swatch {
1066
1143
  border-color: var(--cal-workday);
1067
1144
  color: var(--ys-color-on-solid);
1068
1145
  background: var(--cal-workday);
1069
1146
  }
1147
+ .ys-calendar__legend-item.is-night .ys-calendar__swatch {
1148
+ border-color: var(--cal-night);
1149
+ color: var(--ys-color-on-solid);
1150
+ background: var(--cal-night);
1151
+ }
1152
+ .ys-calendar__label.is-trading,
1153
+ .ys-calendar__legend-item.is-trading .ys-calendar__swatch {
1154
+ border-color: color-mix(in srgb, var(--cal-trading) 55%, transparent);
1155
+ color: color-mix(in srgb, var(--cal-trading) 88%, var(--ys-color-text-1));
1156
+ background: var(--ys-color-primary-soft);
1157
+ }
1070
1158
  .ys-calendar__name {
1071
1159
  overflow: hidden;
1072
1160
  color: color-mix(in srgb, var(--tone) 75%, var(--ys-color-text-1));
@@ -1076,9 +1164,22 @@ function goToday() {
1076
1164
  text-overflow: ellipsis;
1077
1165
  }
1078
1166
  .ys-calendar__cell.is-closed .ys-calendar__name,
1079
- .ys-calendar__cell.is-weekend .ys-calendar__name {
1167
+ .ys-calendar__cell.is-weekend .ys-calendar__name,
1168
+ .ys-calendar__name.is-market-closed {
1080
1169
  color: var(--ys-color-text-3);
1081
1170
  }
1171
+ /* 底行:左边序号(showOrdinal),右边夜盘;贴着格子底部 */
1172
+ .ys-calendar__foot {
1173
+ display: flex;
1174
+ gap: 4px;
1175
+ align-items: center;
1176
+ justify-content: flex-end;
1177
+ min-width: 0;
1178
+ margin-top: auto;
1179
+ }
1180
+ .ys-calendar__foot .ys-calendar__ordinal {
1181
+ margin-right: auto;
1182
+ }
1082
1183
  .ys-calendar__badge {
1083
1184
  display: inline-flex;
1084
1185
  align-items: center;
@@ -1185,6 +1286,9 @@ function goToday() {
1185
1286
  .ys-calendar__legend-item.is-trading {
1186
1287
  --tone: var(--cal-trading);
1187
1288
  }
1289
+ .ys-calendar__legend-item.is-night {
1290
+ --tone: var(--cal-night);
1291
+ }
1188
1292
  .ys-calendar__legend-item.is-workday,
1189
1293
  .ys-calendar__legend-item.is-adjusted {
1190
1294
  --tone: var(--cal-workday);
@@ -1247,6 +1351,47 @@ function goToday() {
1247
1351
  border-radius: 50%;
1248
1352
  background: var(--ys-color-primary);
1249
1353
  }
1354
+ /* 紧凑格子:日期下方蓝色短横 = 开市,短横后的靛紫圆点 = 当晚有夜盘;事件圆点挪到左上角 */
1355
+ .ys-calendar__marks {
1356
+ display: inline-flex;
1357
+ gap: 2px;
1358
+ align-items: center;
1359
+ height: 4px;
1360
+ margin-top: 2px;
1361
+ }
1362
+ .ys-calendar__open-bar {
1363
+ width: 12px;
1364
+ height: 2px;
1365
+ border-radius: 1px;
1366
+ background: var(--cal-trading);
1367
+ }
1368
+ .ys-calendar__night-dot {
1369
+ width: 4px;
1370
+ height: 4px;
1371
+ border-radius: 50%;
1372
+ background: var(--cal-night);
1373
+ }
1374
+ .ys-calendar.is-compact .ys-calendar__dot {
1375
+ position: absolute;
1376
+ top: 3px;
1377
+ left: 3px;
1378
+ }
1379
+ /* 紧凑格子开市短横和夜盘圆点绝对定位在底部,不撑高格子、不让日期行错位 */
1380
+ .ys-calendar.is-compact .ys-calendar__marks {
1381
+ position: absolute;
1382
+ bottom: 3px;
1383
+ left: 50%;
1384
+ transform: translateX(-50%);
1385
+ margin: 0;
1386
+ }
1387
+ .ys-calendar__sr-only {
1388
+ position: absolute;
1389
+ width: 1px;
1390
+ height: 1px;
1391
+ overflow: hidden;
1392
+ clip: rect(0 0 0 0);
1393
+ white-space: nowrap;
1394
+ }
1250
1395
  /* 手机:格子高 44px 好点,月份切换和页面自己的开关(#extra)各占一行 */
1251
1396
  .ys-calendar.is-mobile .ys-calendar__cell {
1252
1397
  min-height: 44px;
@@ -1261,7 +1406,7 @@ function goToday() {
1261
1406
  flex: 1 1 100%;
1262
1407
  }
1263
1408
  .ys-calendar.is-mobile .ys-calendar__nav :deep(.el-date-editor.ys-calendar__month) {
1264
- flex: 1;
1409
+ flex: 1 0 128px;
1265
1410
  width: auto;
1266
1411
  }
1267
1412
  .ys-calendar.is-mobile .ys-calendar__arrow {