@ysgroup/ui 0.1.55 → 0.1.57

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.55",
3
+ "version": "0.1.57",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "peerDependencies": {
13
13
  "@ysgroup/contracts": ">=0.1.50",
14
- "@ysgroup/core": ">=0.1.30",
14
+ "@ysgroup/core": ">=0.1.32",
15
15
  "@ysgroup/theme": ">=0.3.3",
16
16
  "element-plus": ">=2.9",
17
17
  "vue": ">=3.5"
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@ysgroup/contracts": "^0.1.51",
29
- "@ysgroup/core": "^0.1.30",
29
+ "@ysgroup/core": "^0.1.32",
30
30
  "@ysgroup/theme": "^0.3.3",
31
31
  "docx-preview": "^0.4.1"
32
32
  }
@@ -0,0 +1,937 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 月历:两种视图——「休班」标放假、调休上班和节日名;「交易日」只回答开不开市:交易日左侧主色竖条、右上角写本月
4
+ * 第几个交易日,节前最后、节后首日、月初、月末这几个关键交易日加小标签,休市日(周末、放假、调休上班的周末)斜纹底写「休市」。
5
+ *
6
+ * - 日期信息(days)由服务端 ys_base.calendar 下发,组件只显示,不自己按周一到周五猜;某天 covered 为 false 表示这一年
7
+ * 还没有放假安排,顶部写明、格子不标休班也不标交易日。交易日标记由 @ysgroup/core 的 ysTradingMarks 按 trading 字段推出。
8
+ * - v-model 是选中日期,v-model:month 是显示的月份(`YYYY-MM`);翻月后按 ysMonthRange(month) 取这一屏的日期信息。
9
+ * - mark="work" | "trading" 选视图(旧的 trading 属性等于 mark="trading");summary 在顶部显示本月统计。
10
+ * - 键盘:方向键移动一天或一周,PageUp / PageDown 翻月,Home / End 到本周一 / 周日,Enter 或空格选中;跨月自动翻页。
11
+ * - 事件条(events)每格最多 maxEvents 条,其余收成「+N」(触发 more);要完全自定义格子内容用 #day 插槽。
12
+ */
13
+ import { computed, nextTick, ref, watch } from "vue";
14
+ import {
15
+ YS_DAY_KIND_LABELS,
16
+ YS_TRADING_TAG_LABELS,
17
+ YS_WEEKDAY_LABELS,
18
+ ysAddDays,
19
+ ysDateTitle,
20
+ ysIsDate,
21
+ ysMonthGrid,
22
+ ysMonthOf,
23
+ ysMonthSummary,
24
+ ysShiftMonth,
25
+ ysToday,
26
+ ysTradingMarks,
27
+ ysWeekday,
28
+ type YsCalendarDay,
29
+ type YsMonthCell,
30
+ type YsTradingMark,
31
+ } from "@ysgroup/core";
32
+
33
+ export interface YsCalendarEvent {
34
+ date: string;
35
+ title: string;
36
+ id?: string | number;
37
+ tone?: "primary" | "success" | "warning" | "danger" | "info";
38
+ }
39
+
40
+ const props = withDefaults(
41
+ defineProps<{
42
+ modelValue?: string;
43
+ month?: string;
44
+ days?: readonly YsCalendarDay[];
45
+ events?: readonly YsCalendarEvent[];
46
+ today?: string;
47
+ loading?: boolean;
48
+ size?: "default" | "small";
49
+ /** 视图:work 休班(默认)、trading 交易日。 */
50
+ mark?: "work" | "trading";
51
+ /** 旧写法,等于 mark="trading"。 */
52
+ trading?: boolean;
53
+ /** 顶部显示本月统计(休班视图:工作日、放假、调休上班;交易日视图:交易日、休市)。 */
54
+ summary?: boolean;
55
+ maxEvents?: number;
56
+ /** 不能选的日期(如非交易日):变淡、点了不选中。 */
57
+ disabledDate?: (date: string, info?: YsCalendarDay) => boolean;
58
+ /** 显示底部图例;默认有日期信息时显示。 */
59
+ legend?: boolean | null;
60
+ }>(),
61
+ {
62
+ modelValue: "",
63
+ month: "",
64
+ days: () => [],
65
+ events: () => [],
66
+ today: "",
67
+ loading: false,
68
+ size: "default",
69
+ mark: undefined,
70
+ trading: false,
71
+ summary: false,
72
+ maxEvents: 3,
73
+ disabledDate: undefined,
74
+ legend: null,
75
+ },
76
+ );
77
+
78
+ const emit = defineEmits<{
79
+ "update:modelValue": [date: string];
80
+ "update:month": [month: string];
81
+ select: [date: string, info: YsCalendarDay | undefined];
82
+ more: [date: string];
83
+ }>();
84
+
85
+ const todayText = computed(() => props.today || ysToday());
86
+ const innerMonth = ref(
87
+ props.month || ysMonthOf(props.modelValue || todayText.value),
88
+ );
89
+ watch(
90
+ () => props.month,
91
+ (value) => {
92
+ if (value && value !== innerMonth.value) innerMonth.value = value;
93
+ },
94
+ );
95
+ const shownMonth = computed(() => innerMonth.value);
96
+ const cells = computed(() => ysMonthGrid(shownMonth.value));
97
+ const rows = computed(() =>
98
+ Array.from({ length: 6 }, (_, row) =>
99
+ cells.value.slice(row * 7, row * 7 + 7),
100
+ ),
101
+ );
102
+ const infoMap = computed(
103
+ () => new Map(props.days.map((item) => [item.date, item])),
104
+ );
105
+ const eventMap = computed(() => {
106
+ const map = new Map<string, YsCalendarEvent[]>();
107
+ for (const item of props.events) {
108
+ const list = map.get(item.date);
109
+ if (list) list.push(item);
110
+ else map.set(item.date, [item]);
111
+ }
112
+ return map;
113
+ });
114
+ const small = computed(() => props.size === "small");
115
+ const tradingView = computed(
116
+ () => (props.mark ?? (props.trading ? "trading" : "work")) === "trading",
117
+ );
118
+ const marks = computed(() =>
119
+ tradingView.value
120
+ ? ysTradingMarks(props.days)
121
+ : new Map<string, YsTradingMark>(),
122
+ );
123
+
124
+ /** 这一屏里还没有放假安排的年份。 */
125
+ const missingYears = computed(() => {
126
+ const years = new Set<string>();
127
+ for (const cell of cells.value)
128
+ if (infoMap.value.get(cell.date)?.covered === false)
129
+ years.add(cell.date.slice(0, 4));
130
+ return [...years].sort();
131
+ });
132
+ const showLegend = computed(
133
+ () => !small.value && (props.legend ?? props.days.length > 0),
134
+ );
135
+ const todayVisible = computed(() =>
136
+ cells.value.some((cell) => cell.date === todayText.value),
137
+ );
138
+
139
+ /** 顶部统计:拆成「名称 + 数字」几段,数字加粗。月份信息不全时不显示。 */
140
+ const summaryParts = computed(() => {
141
+ if (!props.summary || small.value) return [];
142
+ const value = ysMonthSummary(props.days, shownMonth.value);
143
+ if (!value.complete) return [];
144
+ if (tradingView.value)
145
+ return [
146
+ { label: "交易日", value: value.trading },
147
+ { label: "休市", value: value.closed },
148
+ ];
149
+ const parts = [{ label: "工作日", value: value.workdays }];
150
+ if (value.holidays) parts.push({ label: "放假", value: value.holidays });
151
+ if (value.adjusted) parts.push({ label: "调休上班", value: value.adjusted });
152
+ return parts;
153
+ });
154
+
155
+ function setMonth(month: string) {
156
+ if (!month || month === innerMonth.value) return;
157
+ innerMonth.value = month;
158
+ emit("update:month", month);
159
+ }
160
+
161
+ // ---------- 格子状态 ----------
162
+ function info(date: string): YsCalendarDay | undefined {
163
+ return infoMap.value.get(date);
164
+ }
165
+ function eventsOf(date: string): YsCalendarEvent[] {
166
+ return eventMap.value.get(date) ?? [];
167
+ }
168
+ function covered(date: string): boolean {
169
+ const item = info(date);
170
+ return Boolean(item) && item?.covered !== false;
171
+ }
172
+ function badge(date: string): "休" | "班" | "" {
173
+ if (tradingView.value || !covered(date)) return "";
174
+ const kind = info(date)?.kind;
175
+ return kind === "holiday" ? "休" : kind === "adjusted" ? "班" : "";
176
+ }
177
+ function isRest(cell: YsMonthCell): boolean {
178
+ const item = info(cell.date);
179
+ if (item && item.covered !== false)
180
+ return item.kind === "holiday" || item.kind === "weekend";
181
+ return cell.weekday >= 5;
182
+ }
183
+ function isTrading(date: string): boolean {
184
+ return tradingView.value && covered(date) && Boolean(info(date)?.trading);
185
+ }
186
+ function isClosed(date: string): boolean {
187
+ return tradingView.value && covered(date) && !info(date)?.trading;
188
+ }
189
+ /** 格子第二行:休班视图写节日名;交易日视图休市日写「休市」或「端午节 · 休市」。 */
190
+ function subline(date: string): string {
191
+ if (!covered(date)) return "";
192
+ const item = info(date);
193
+ if (tradingView.value)
194
+ return isClosed(date) ? (item?.name ? `${item.name} · 休市` : "休市") : "";
195
+ return item?.name ?? "";
196
+ }
197
+ function markOf(date: string): YsTradingMark | undefined {
198
+ return marks.value.get(date);
199
+ }
200
+ function disabled(date: string): boolean {
201
+ return Boolean(props.disabledDate?.(date, info(date)));
202
+ }
203
+ function ariaLabel(cell: YsMonthCell): string {
204
+ const item = info(cell.date);
205
+ const parts = [ysDateTitle(cell.date)];
206
+ if (item?.covered === false) parts.push("放假安排还没有");
207
+ else if (item) {
208
+ parts.push(
209
+ item.name
210
+ ? `${YS_DAY_KIND_LABELS[item.kind]} ${item.name}`
211
+ : YS_DAY_KIND_LABELS[item.kind],
212
+ );
213
+ if (tradingView.value) {
214
+ const mark = markOf(cell.date);
215
+ parts.push(
216
+ item.trading
217
+ ? mark?.ordinal
218
+ ? `本月第 ${mark.ordinal} 个交易日`
219
+ : "交易日"
220
+ : "休市",
221
+ );
222
+ for (const tag of mark?.tags ?? [])
223
+ parts.push(YS_TRADING_TAG_LABELS[tag].full);
224
+ }
225
+ }
226
+ if (cell.date === todayText.value) parts.push("今天");
227
+ const count = eventsOf(cell.date).length;
228
+ if (count) parts.push(`${count} 项`);
229
+ if (disabled(cell.date)) parts.push("不可选");
230
+ return parts.join(",");
231
+ }
232
+
233
+ // ---------- 选择与键盘 ----------
234
+ const grid = ref<HTMLElement | null>(null);
235
+ const focusDate = ref(
236
+ ysIsDate(props.modelValue) ? props.modelValue : todayText.value,
237
+ );
238
+ watch(
239
+ () => props.modelValue,
240
+ (value) => {
241
+ if (ysIsDate(value)) focusDate.value = value;
242
+ },
243
+ );
244
+ /** 可以 Tab 进来的那一格:焦点日在本屏就用它,否则用本月 1 日。 */
245
+ const tabDate = computed(() =>
246
+ cells.value.some((cell) => cell.date === focusDate.value)
247
+ ? focusDate.value
248
+ : `${shownMonth.value}-01`,
249
+ );
250
+
251
+ function select(date: string) {
252
+ focusDate.value = date;
253
+ if (!date.startsWith(shownMonth.value)) setMonth(ysMonthOf(date));
254
+ if (disabled(date)) return;
255
+ emit("update:modelValue", date);
256
+ emit("select", date, info(date));
257
+ }
258
+
259
+ function moveFocus(date: string) {
260
+ focusDate.value = date;
261
+ if (!date.startsWith(shownMonth.value)) setMonth(ysMonthOf(date));
262
+ void nextTick(() =>
263
+ grid.value?.querySelector<HTMLElement>(`[data-date="${date}"]`)?.focus(),
264
+ );
265
+ }
266
+
267
+ function onKeydown(event: KeyboardEvent) {
268
+ const current = focusDate.value;
269
+ const weekday = ysWeekday(current);
270
+ const moves: Record<string, () => string> = {
271
+ ArrowLeft: () => ysAddDays(current, -1),
272
+ ArrowRight: () => ysAddDays(current, 1),
273
+ ArrowUp: () => ysAddDays(current, -7),
274
+ ArrowDown: () => ysAddDays(current, 7),
275
+ Home: () => ysAddDays(current, -weekday),
276
+ End: () => ysAddDays(current, 6 - weekday),
277
+ PageUp: () => shiftKeepDay(current, -1),
278
+ PageDown: () => shiftKeepDay(current, 1),
279
+ };
280
+ if (event.key === "Enter" || event.key === " ") {
281
+ event.preventDefault();
282
+ select(current);
283
+ return;
284
+ }
285
+ const move = moves[event.key];
286
+ if (!move) return;
287
+ event.preventDefault();
288
+ moveFocus(move());
289
+ }
290
+
291
+ /** 翻月时保持几号;下个月没有这一天(如 1 月 31 日 → 2 月)就落在月末。 */
292
+ function shiftKeepDay(date: string, delta: number): string {
293
+ const month = ysShiftMonth(ysMonthOf(date), delta);
294
+ let day = Number(date.slice(8));
295
+ while (day > 28 && !ysIsDate(`${month}-${String(day).padStart(2, "0")}`))
296
+ day -= 1;
297
+ return `${month}-${String(day).padStart(2, "0")}`;
298
+ }
299
+
300
+ function goToday() {
301
+ setMonth(ysMonthOf(todayText.value));
302
+ select(todayText.value);
303
+ }
304
+ </script>
305
+
306
+ <template>
307
+ <div
308
+ class="ys-calendar"
309
+ :class="{ 'is-small': small, 'is-trading-view': tradingView }"
310
+ >
311
+ <header class="ys-calendar__head">
312
+ <div class="ys-calendar__nav">
313
+ <el-button
314
+ text
315
+ :size="small ? 'small' : 'default'"
316
+ aria-label="上个月"
317
+ class="ys-calendar__arrow"
318
+ @click="setMonth(ysShiftMonth(shownMonth, -1))"
319
+ >‹</el-button
320
+ >
321
+ <el-date-picker
322
+ :model-value="shownMonth"
323
+ type="month"
324
+ value-format="YYYY-MM"
325
+ format="YYYY 年 M 月"
326
+ :clearable="false"
327
+ :editable="false"
328
+ :size="small ? 'small' : 'default'"
329
+ class="ys-calendar__month"
330
+ aria-label="选择月份"
331
+ @update:model-value="(value: string) => setMonth(value)"
332
+ />
333
+ <el-button
334
+ text
335
+ :size="small ? 'small' : 'default'"
336
+ aria-label="下个月"
337
+ class="ys-calendar__arrow"
338
+ @click="setMonth(ysShiftMonth(shownMonth, 1))"
339
+ >›</el-button
340
+ >
341
+ <el-button :size="small ? 'small' : 'default'" @click="goToday"
342
+ >今天</el-button
343
+ >
344
+ </div>
345
+ <div
346
+ v-if="summaryParts.length"
347
+ class="ys-calendar__summary"
348
+ aria-label="本月统计"
349
+ >
350
+ <span
351
+ v-for="part in summaryParts"
352
+ :key="part.label"
353
+ class="ys-calendar__summary-item"
354
+ ><span>{{ part.label }}</span
355
+ ><strong>{{ part.value }}</strong></span
356
+ >
357
+ </div>
358
+ <div v-if="$slots.extra" class="ys-calendar__extra">
359
+ <slot name="extra" />
360
+ </div>
361
+ </header>
362
+
363
+ <p
364
+ v-if="missingYears.length && !small"
365
+ class="ys-calendar__missing"
366
+ role="status"
367
+ >
368
+ {{ missingYears.join("、") }} 年的放假安排还没有(国务院办公厅一般在上一年
369
+ 10–11 月发布),这些日期暂不标休班和交易日。
370
+ </p>
371
+
372
+ <div
373
+ ref="grid"
374
+ v-loading="loading"
375
+ class="ys-calendar__grid"
376
+ role="grid"
377
+ :aria-label="`${shownMonth.slice(0, 4)} 年 ${Number(shownMonth.slice(5))} 月`"
378
+ @keydown="onKeydown"
379
+ >
380
+ <div class="ys-calendar__row is-head" role="row">
381
+ <div
382
+ v-for="(label, index) in YS_WEEKDAY_LABELS"
383
+ :key="label"
384
+ class="ys-calendar__weekday"
385
+ :class="{ 'is-weekend': index >= 5 }"
386
+ role="columnheader"
387
+ >
388
+ {{ small ? label : `周${label}` }}
389
+ </div>
390
+ </div>
391
+ <div
392
+ v-for="(row, rowIndex) in rows"
393
+ :key="rowIndex"
394
+ class="ys-calendar__row"
395
+ role="row"
396
+ >
397
+ <div
398
+ v-for="cell in row"
399
+ :key="cell.date"
400
+ class="ys-calendar__cell"
401
+ role="gridcell"
402
+ :data-date="cell.date"
403
+ :tabindex="cell.date === tabDate ? 0 : -1"
404
+ :aria-selected="cell.date === modelValue"
405
+ :aria-disabled="disabled(cell.date) || undefined"
406
+ :aria-label="ariaLabel(cell)"
407
+ :title="small ? ariaLabel(cell) : undefined"
408
+ :class="{
409
+ 'is-outside': !cell.inMonth,
410
+ 'is-today': cell.date === todayText,
411
+ 'is-selected': cell.date === modelValue,
412
+ 'is-rest': isRest(cell),
413
+ 'is-holiday':
414
+ !tradingView &&
415
+ covered(cell.date) &&
416
+ info(cell.date)?.kind === 'holiday',
417
+ 'is-adjusted':
418
+ !tradingView &&
419
+ covered(cell.date) &&
420
+ info(cell.date)?.kind === 'adjusted',
421
+ 'is-trading': isTrading(cell.date),
422
+ 'is-closed': isClosed(cell.date),
423
+ 'is-uncovered': info(cell.date)?.covered === false,
424
+ 'is-disabled': disabled(cell.date),
425
+ }"
426
+ @click="select(cell.date)"
427
+ @focus="focusDate = cell.date"
428
+ >
429
+ <slot
430
+ name="day"
431
+ :cell="cell"
432
+ :info="info(cell.date)"
433
+ :events="eventsOf(cell.date)"
434
+ :mark="markOf(cell.date)"
435
+ >
436
+ <div class="ys-calendar__top">
437
+ <span class="ys-calendar__date">{{
438
+ Number(cell.date.slice(8))
439
+ }}</span>
440
+ <span
441
+ v-if="badge(cell.date)"
442
+ class="ys-calendar__badge"
443
+ :class="badge(cell.date) === '休' ? 'is-off' : 'is-work'"
444
+ >{{ badge(cell.date) }}</span
445
+ >
446
+ <span
447
+ v-else-if="!small && markOf(cell.date)?.ordinal"
448
+ class="ys-calendar__ordinal"
449
+ aria-hidden="true"
450
+ >{{ markOf(cell.date)?.ordinal }}</span
451
+ >
452
+ </div>
453
+ <template v-if="!small">
454
+ <div v-if="subline(cell.date)" class="ys-calendar__name">
455
+ {{ subline(cell.date) }}
456
+ </div>
457
+ <div
458
+ v-if="markOf(cell.date)?.tags.length"
459
+ class="ys-calendar__tags"
460
+ >
461
+ <span
462
+ v-for="tag in markOf(cell.date)?.tags"
463
+ :key="tag"
464
+ class="ys-calendar__tag"
465
+ :class="`is-${tag}`"
466
+ >{{ YS_TRADING_TAG_LABELS[tag].short }}</span
467
+ >
468
+ </div>
469
+ <ul v-if="eventsOf(cell.date).length" class="ys-calendar__events">
470
+ <li
471
+ v-for="item in eventsOf(cell.date).slice(0, maxEvents)"
472
+ :key="item.id ?? item.title"
473
+ class="ys-calendar__event"
474
+ :class="`is-${item.tone ?? 'primary'}`"
475
+ :title="item.title"
476
+ >
477
+ {{ item.title }}
478
+ </li>
479
+ <li v-if="eventsOf(cell.date).length > maxEvents">
480
+ <button
481
+ type="button"
482
+ class="ys-calendar__more"
483
+ tabindex="-1"
484
+ @click.stop="emit('more', cell.date)"
485
+ v-text="`+${eventsOf(cell.date).length - maxEvents}`"
486
+ />
487
+ </li>
488
+ </ul>
489
+ </template>
490
+ <span
491
+ v-else-if="eventsOf(cell.date).length"
492
+ class="ys-calendar__dot"
493
+ aria-hidden="true"
494
+ />
495
+ </slot>
496
+ </div>
497
+ </div>
498
+ </div>
499
+
500
+ <footer v-if="showLegend" class="ys-calendar__legend">
501
+ <template v-if="tradingView">
502
+ <span
503
+ ><i
504
+ class="ys-calendar__swatch is-trading"
505
+ />交易日(右上角是本月第几个)</span
506
+ >
507
+ <span
508
+ ><i
509
+ class="ys-calendar__swatch is-closed"
510
+ />休市:周末、放假和调休上班的周末</span
511
+ >
512
+ <span
513
+ ><i class="ys-calendar__tag is-pre-holiday">节前最后</i
514
+ ><i class="ys-calendar__tag is-month-last">月末最后</i
515
+ >关键交易日</span
516
+ >
517
+ </template>
518
+ <template v-else>
519
+ <span><i class="ys-calendar__badge is-off">休</i>放假</span>
520
+ <span><i class="ys-calendar__badge is-work">班</i>调休上班</span>
521
+ </template>
522
+ <span v-if="todayVisible" class="ys-calendar__legend-today">今天</span>
523
+ </footer>
524
+ </div>
525
+ </template>
526
+
527
+ <style scoped>
528
+ .ys-calendar {
529
+ --cal-rest: color-mix(
530
+ in srgb,
531
+ var(--ys-color-success) 82%,
532
+ var(--ys-color-text-1)
533
+ );
534
+ --cal-work: color-mix(
535
+ in srgb,
536
+ var(--ys-color-warning) 80%,
537
+ var(--ys-color-text-1)
538
+ );
539
+ --cal-bar: color-mix(in srgb, var(--ys-color-primary) 75%, transparent);
540
+ --cal-stripe: repeating-linear-gradient(
541
+ 135deg,
542
+ color-mix(in srgb, var(--ys-color-text-3) 10%, transparent) 0 5px,
543
+ transparent 5px 11px
544
+ );
545
+ display: flex;
546
+ flex-direction: column;
547
+ gap: 8px;
548
+ min-width: 0;
549
+ }
550
+ .ys-calendar__head {
551
+ display: flex;
552
+ flex-wrap: wrap;
553
+ gap: 8px 16px;
554
+ align-items: center;
555
+ }
556
+ .ys-calendar__nav {
557
+ display: flex;
558
+ gap: 4px;
559
+ align-items: center;
560
+ }
561
+ .ys-calendar__arrow {
562
+ width: 28px;
563
+ padding: 0;
564
+ font-size: 18px;
565
+ }
566
+ .ys-calendar__nav :deep(.el-date-editor.ys-calendar__month) {
567
+ width: 128px;
568
+ }
569
+ .ys-calendar.is-small
570
+ .ys-calendar__nav
571
+ :deep(.el-date-editor.ys-calendar__month) {
572
+ width: 112px;
573
+ }
574
+ .ys-calendar__summary {
575
+ display: flex;
576
+ flex-wrap: wrap;
577
+ gap: 4px 14px;
578
+ color: var(--ys-color-text-2);
579
+ font-size: 12px;
580
+ }
581
+ .ys-calendar__summary-item {
582
+ display: inline-flex;
583
+ gap: 4px;
584
+ align-items: baseline;
585
+ }
586
+ .ys-calendar__summary-item strong {
587
+ color: var(--ys-color-text-1);
588
+ font-size: 14px;
589
+ font-variant-numeric: tabular-nums;
590
+ }
591
+ .ys-calendar__extra {
592
+ display: flex;
593
+ flex-wrap: wrap;
594
+ gap: 8px;
595
+ align-items: center;
596
+ margin-left: auto;
597
+ }
598
+ .ys-calendar__missing {
599
+ margin: 0;
600
+ padding: 6px 10px;
601
+ border-left: 3px solid var(--ys-color-warning);
602
+ border-radius: var(--ys-radius-s);
603
+ color: var(--ys-color-text-2);
604
+ background: color-mix(in srgb, var(--ys-color-warning) 8%, transparent);
605
+ font-size: 12px;
606
+ line-height: 1.6;
607
+ }
608
+
609
+ /* 网格 */
610
+ .ys-calendar__grid {
611
+ display: flex;
612
+ flex-direction: column;
613
+ border: 1px solid var(--ys-color-border);
614
+ border-radius: var(--ys-radius-m);
615
+ overflow: hidden;
616
+ background: var(--ys-color-bg-elevated);
617
+ }
618
+ .ys-calendar__row {
619
+ display: grid;
620
+ flex: 1;
621
+ grid-template-columns: repeat(7, minmax(0, 1fr));
622
+ }
623
+ .ys-calendar__row + .ys-calendar__row {
624
+ border-top: 1px solid var(--ys-color-border);
625
+ }
626
+ .ys-calendar__row.is-head {
627
+ flex: none;
628
+ background: var(--ys-color-bg);
629
+ }
630
+ .ys-calendar__weekday {
631
+ padding: 6px 8px;
632
+ color: var(--ys-color-text-2);
633
+ font-size: 12px;
634
+ font-weight: 600;
635
+ }
636
+ .ys-calendar__weekday.is-weekend {
637
+ color: var(--cal-rest);
638
+ }
639
+ .ys-calendar__cell {
640
+ --cal-ring: 0 0 0 0 transparent;
641
+ --cal-left: 0 0 0 0 transparent;
642
+ position: relative;
643
+ display: flex;
644
+ flex-direction: column;
645
+ gap: 3px;
646
+ min-width: 0;
647
+ /* 格子随宽度略微变高,大屏不显得扁 */
648
+ min-height: clamp(88px, 6.8vw, 128px);
649
+ padding: 6px 6px 6px 8px;
650
+ cursor: pointer;
651
+ outline: none;
652
+ box-shadow: var(--cal-left), var(--cal-ring);
653
+ transition:
654
+ background-color 0.15s ease,
655
+ box-shadow 0.15s ease;
656
+ }
657
+ .ys-calendar__cell + .ys-calendar__cell {
658
+ border-left: 1px solid var(--ys-color-border);
659
+ }
660
+ .ys-calendar__cell:hover {
661
+ background-color: color-mix(in srgb, var(--ys-color-primary) 4%, transparent);
662
+ }
663
+ .ys-calendar__cell:focus-visible {
664
+ --cal-ring: inset 0 0 0 2px var(--ys-color-primary);
665
+ }
666
+ .ys-calendar__cell.is-rest:not(.is-selected) {
667
+ background-color: color-mix(in srgb, var(--ys-color-text-3) 4%, transparent);
668
+ }
669
+ .ys-calendar__cell.is-holiday:not(.is-selected) {
670
+ background-color: color-mix(in srgb, var(--ys-color-success) 7%, transparent);
671
+ }
672
+ .ys-calendar__cell.is-adjusted:not(.is-selected) {
673
+ background-color: color-mix(in srgb, var(--ys-color-warning) 7%, transparent);
674
+ }
675
+ /* 交易日视图:交易日左侧竖条,休市斜纹 */
676
+ .ys-calendar__cell.is-trading {
677
+ --cal-left: inset 3px 0 0 var(--cal-bar);
678
+ }
679
+ .ys-calendar__cell.is-closed {
680
+ background-image: var(--cal-stripe);
681
+ }
682
+ .ys-calendar__cell.is-closed .ys-calendar__date {
683
+ color: var(--ys-color-text-3);
684
+ }
685
+ .ys-calendar__cell.is-selected {
686
+ --cal-ring: inset 0 0 0 1px
687
+ color-mix(in srgb, var(--ys-color-primary) 60%, transparent);
688
+ background-color: color-mix(
689
+ in srgb,
690
+ var(--ys-color-primary) 11%,
691
+ transparent
692
+ );
693
+ }
694
+ .ys-calendar__cell.is-selected:focus-visible {
695
+ --cal-ring: inset 0 0 0 2px var(--ys-color-primary);
696
+ }
697
+ .ys-calendar__cell.is-outside > * {
698
+ opacity: 0.42;
699
+ }
700
+ .ys-calendar__cell.is-outside.is-trading {
701
+ --cal-left: inset 3px 0 0
702
+ color-mix(in srgb, var(--ys-color-primary) 28%, transparent);
703
+ }
704
+ .ys-calendar__cell.is-disabled {
705
+ cursor: not-allowed;
706
+ }
707
+ .ys-calendar__cell.is-disabled > * {
708
+ opacity: 0.38;
709
+ }
710
+ .ys-calendar__top {
711
+ display: flex;
712
+ gap: 4px;
713
+ align-items: center;
714
+ justify-content: space-between;
715
+ }
716
+ .ys-calendar__date {
717
+ display: inline-flex;
718
+ align-items: center;
719
+ justify-content: center;
720
+ min-width: 24px;
721
+ height: 24px;
722
+ padding: 0 4px;
723
+ border-radius: 999px;
724
+ color: var(--ys-color-text-1);
725
+ font-size: 13px;
726
+ font-variant-numeric: tabular-nums;
727
+ font-weight: 600;
728
+ }
729
+ .ys-calendar__cell.is-rest:not(.is-closed) .ys-calendar__date {
730
+ color: var(--cal-rest);
731
+ }
732
+ .ys-calendar__cell.is-uncovered .ys-calendar__date {
733
+ text-decoration: underline dotted var(--ys-color-text-3);
734
+ text-underline-offset: 3px;
735
+ }
736
+ .ys-calendar__cell.is-today .ys-calendar__date {
737
+ color: var(--ys-color-on-solid);
738
+ background: var(--ys-color-primary);
739
+ }
740
+ .ys-calendar__badge {
741
+ display: inline-flex;
742
+ align-items: center;
743
+ justify-content: center;
744
+ width: 18px;
745
+ height: 18px;
746
+ border-radius: var(--ys-radius-s);
747
+ font-size: 11px;
748
+ font-style: normal;
749
+ font-weight: 600;
750
+ line-height: 1;
751
+ }
752
+ .ys-calendar__badge.is-off {
753
+ color: var(--cal-rest);
754
+ background: color-mix(in srgb, var(--ys-color-success) 16%, transparent);
755
+ }
756
+ .ys-calendar__badge.is-work {
757
+ color: var(--cal-work);
758
+ background: color-mix(in srgb, var(--ys-color-warning) 18%, transparent);
759
+ }
760
+ .ys-calendar__ordinal {
761
+ min-width: 20px;
762
+ color: color-mix(
763
+ in srgb,
764
+ var(--ys-color-primary) 70%,
765
+ var(--ys-color-text-3)
766
+ );
767
+ font-size: 11px;
768
+ font-variant-numeric: tabular-nums;
769
+ font-weight: 600;
770
+ text-align: right;
771
+ }
772
+ .ys-calendar__name {
773
+ overflow: hidden;
774
+ color: var(--cal-rest);
775
+ font-size: 11px;
776
+ line-height: 1.5;
777
+ white-space: nowrap;
778
+ text-overflow: ellipsis;
779
+ }
780
+ .ys-calendar__cell.is-adjusted .ys-calendar__name {
781
+ color: var(--cal-work);
782
+ }
783
+ .ys-calendar__cell.is-closed .ys-calendar__name {
784
+ color: var(--ys-color-text-3);
785
+ }
786
+ .ys-calendar__tags {
787
+ display: flex;
788
+ flex-wrap: wrap;
789
+ gap: 3px;
790
+ }
791
+ .ys-calendar__tag {
792
+ --tone: var(--ys-color-primary);
793
+ padding: 0 5px;
794
+ border-radius: var(--ys-radius-s);
795
+ color: color-mix(in srgb, var(--tone) 82%, var(--ys-color-text-1));
796
+ background: color-mix(in srgb, var(--tone) 13%, transparent);
797
+ font-size: 11px;
798
+ font-style: normal;
799
+ line-height: 17px;
800
+ white-space: nowrap;
801
+ }
802
+ .ys-calendar__tag.is-pre-holiday {
803
+ --tone: var(--ys-color-warning);
804
+ }
805
+ .ys-calendar__tag.is-post-holiday {
806
+ --tone: var(--ys-color-success);
807
+ }
808
+ .ys-calendar__events {
809
+ display: flex;
810
+ flex-direction: column;
811
+ gap: 2px;
812
+ min-width: 0;
813
+ margin: 2px 0 0;
814
+ padding: 0;
815
+ list-style: none;
816
+ }
817
+ .ys-calendar__event {
818
+ --tone: var(--ys-color-primary);
819
+ overflow: hidden;
820
+ padding: 1px 6px;
821
+ border-left: 3px solid var(--tone);
822
+ border-radius: var(--ys-radius-s);
823
+ color: var(--ys-color-text-1);
824
+ background: color-mix(in srgb, var(--tone) 10%, transparent);
825
+ font-size: 12px;
826
+ line-height: 18px;
827
+ white-space: nowrap;
828
+ text-overflow: ellipsis;
829
+ }
830
+ .ys-calendar__event.is-success {
831
+ --tone: var(--ys-color-success);
832
+ }
833
+ .ys-calendar__event.is-warning {
834
+ --tone: var(--ys-color-warning);
835
+ }
836
+ .ys-calendar__event.is-danger {
837
+ --tone: var(--ys-color-danger);
838
+ }
839
+ .ys-calendar__event.is-info {
840
+ --tone: var(--ys-color-text-3);
841
+ }
842
+ .ys-calendar__more {
843
+ padding: 0 6px;
844
+ border: 0;
845
+ border-radius: var(--ys-radius-s);
846
+ color: var(--ys-color-primary);
847
+ background: none;
848
+ font: inherit;
849
+ font-size: 12px;
850
+ line-height: 18px;
851
+ cursor: pointer;
852
+ }
853
+ .ys-calendar__more:hover {
854
+ background: color-mix(in srgb, var(--ys-color-primary) 10%, transparent);
855
+ }
856
+
857
+ /* 图例 */
858
+ .ys-calendar__legend {
859
+ display: flex;
860
+ flex-wrap: wrap;
861
+ gap: 4px 18px;
862
+ align-items: center;
863
+ color: var(--ys-color-text-3);
864
+ font-size: 12px;
865
+ }
866
+ .ys-calendar__legend > span {
867
+ display: inline-flex;
868
+ gap: 5px;
869
+ align-items: center;
870
+ }
871
+ .ys-calendar__swatch {
872
+ display: inline-block;
873
+ width: 18px;
874
+ height: 14px;
875
+ border: 1px solid var(--ys-color-border);
876
+ border-radius: 3px;
877
+ background: var(--ys-color-bg-elevated);
878
+ }
879
+ .ys-calendar__swatch.is-trading {
880
+ box-shadow: inset 3px 0 0 var(--cal-bar);
881
+ }
882
+ .ys-calendar__swatch.is-closed {
883
+ background-image: var(--cal-stripe);
884
+ }
885
+ .ys-calendar__legend-today::before {
886
+ display: inline-block;
887
+ width: 10px;
888
+ height: 10px;
889
+ border-radius: 50%;
890
+ background: var(--ys-color-primary);
891
+ content: "";
892
+ }
893
+
894
+ /* 迷你模式:只有日期、休班角标(交易日视图为休市斜纹)和事件圆点,悬停看完整信息 */
895
+ .ys-calendar.is-small .ys-calendar__weekday {
896
+ padding: 4px 0;
897
+ text-align: center;
898
+ }
899
+ .ys-calendar.is-small .ys-calendar__cell {
900
+ align-items: center;
901
+ justify-content: center;
902
+ min-height: 36px;
903
+ padding: 2px;
904
+ }
905
+ .ys-calendar.is-small .ys-calendar__cell.is-trading {
906
+ --cal-left: 0 0 0 0 transparent;
907
+ }
908
+ .ys-calendar.is-small .ys-calendar__cell + .ys-calendar__cell {
909
+ border-left: 0;
910
+ }
911
+ .ys-calendar.is-small .ys-calendar__row + .ys-calendar__row {
912
+ border-top: 0;
913
+ }
914
+ /* 角标跟着日期数字:top 只包住数字,角标挂在数字右上角(不超出最右一列) */
915
+ .ys-calendar.is-small .ys-calendar__top {
916
+ position: relative;
917
+ display: inline-flex;
918
+ }
919
+ .ys-calendar.is-small .ys-calendar__date {
920
+ font-size: 12px;
921
+ font-weight: 500;
922
+ }
923
+ .ys-calendar.is-small .ys-calendar__badge {
924
+ position: absolute;
925
+ top: -5px;
926
+ right: -6px;
927
+ width: 12px;
928
+ height: 12px;
929
+ font-size: 9px;
930
+ }
931
+ .ys-calendar__dot {
932
+ width: 4px;
933
+ height: 4px;
934
+ border-radius: 50%;
935
+ background: var(--ys-color-primary);
936
+ }
937
+ </style>
package/src/index.ts CHANGED
@@ -3,13 +3,19 @@
3
3
  export { default as YsCrudTable } from "./components/YsCrudTable.vue";
4
4
  export { default as YsTableToolbar } from "./components/YsTableToolbar.vue";
5
5
  export { default as YsStatusFilter } from "./components/YsStatusFilter.vue";
6
+ export { default as YsCalendar } from "./components/YsCalendar.vue";
7
+ export type { YsCalendarEvent } from "./components/YsCalendar.vue";
6
8
  export { default as YsTablePagination } from "./components/YsTablePagination.vue";
7
9
  export { default as YsRowActionMenu } from "./components/YsRowActionMenu.vue";
8
10
  export type { YsRowAction } from "./components/YsRowActionMenu.vue";
9
11
  export { default as YsFormDialog } from "./components/YsFormDialog.vue";
10
12
  export { default as YsSelect } from "./components/YsSelect.vue";
11
13
  export { default as YsTreeSelect } from "./components/YsTreeSelect.vue";
12
- export { useYsOptionFilter, ysTreeFilter, type YsOptionFilter } from "./optionFilter";
14
+ export {
15
+ useYsOptionFilter,
16
+ ysTreeFilter,
17
+ type YsOptionFilter,
18
+ } from "./optionFilter";
13
19
  export { default as YsDialog } from "./components/YsDialog.vue";
14
20
  export { dialogTitle, ysConfirm, type YsConfirmOptions } from "./dialog";
15
21
  export { default as YsLoadError } from "./components/YsLoadError.vue";