@ysgroup/ui 0.1.57 → 0.1.59

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.
@@ -0,0 +1,554 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 选中日详情卡:放在 YsCalendar 旁边,介绍选中那天的情况。
4
+ *
5
+ * - 头部:日期方块(颜色跟月历一致:工作日、法定补班浅绿,放假浅橙,休息灰)、完整日期、离今天几天、农历和干支生肖、
6
+ * 传统节日和节气。
7
+ * - 状态:工作日 / 法定补班 / 休息 / 放假、交易日 / 休市,以及节前最后、节后首日、月初、月末这些关键交易日(全称)。
8
+ * - 本月位置:几月第 N 个工作日、第 N 个交易日(带进度条),放假时写「国庆节假期第 3 天,共 8 天」。
9
+ * - 当天的事项(events),以及默认插槽放页面自己的内容(如上一个、下一个交易日和 T+N 推算)。
10
+ * - 数据都由 @ysgroup/core 的 ysDayDetail 从服务端下发的 days 推出,组件只显示;农历用 ysLunar 现算,只用于显示。
11
+ */
12
+ import { computed } from "vue";
13
+ import {
14
+ YS_TRADING_TAG_LABELS,
15
+ ysDateTitle,
16
+ ysDayDetail,
17
+ ysDaysBetween,
18
+ ysIsDate,
19
+ ysToday,
20
+ ysWeekdayLabel,
21
+ type YsCalendarDay,
22
+ } from "@ysgroup/core";
23
+ import type {
24
+ YsCalendarEvent,
25
+ YsCalendarLabels,
26
+ YsCalendarStatus,
27
+ } from "./YsCalendar.vue";
28
+
29
+ const DEFAULT_LABELS: YsCalendarLabels = {
30
+ trading: "交易日",
31
+ closed: "休市",
32
+ workday: "工作日",
33
+ adjusted: "法定补班",
34
+ weekend: "休息",
35
+ holiday: "放假",
36
+ };
37
+
38
+ const props = withDefaults(
39
+ defineProps<{
40
+ /** 选中的日期 YYYY-MM-DD。 */
41
+ date: string;
42
+ /** 这一屏的日期信息(和传给 YsCalendar 的 days 相同)。 */
43
+ days?: readonly YsCalendarDay[];
44
+ events?: readonly YsCalendarEvent[];
45
+ today?: string;
46
+ /** 改状态文字,和 YsCalendar 的 labels 一致。 */
47
+ labels?: Partial<YsCalendarLabels>;
48
+ /** 显示交易日相关内容(交易日 / 休市、第几个交易日、关键交易日);不涉及交易的系统可以关掉。 */
49
+ trading?: boolean;
50
+ }>(),
51
+ {
52
+ days: () => [],
53
+ events: () => [],
54
+ today: "",
55
+ labels: () => ({}),
56
+ trading: true,
57
+ },
58
+ );
59
+
60
+ const labelText = computed<YsCalendarLabels>(() => ({
61
+ ...DEFAULT_LABELS,
62
+ ...props.labels,
63
+ }));
64
+ const valid = computed(() => ysIsDate(props.date));
65
+ const detail = computed(() => ysDayDetail(props.days, props.date));
66
+ const info = computed(() => detail.value.info);
67
+ const covered = computed(() =>
68
+ Boolean(info.value && info.value.covered !== false),
69
+ );
70
+ const monthNumber = computed(() => Number(props.date.slice(5, 7)));
71
+ const dayNumber = computed(() => Number(props.date.slice(8, 10)));
72
+
73
+ /** 工作状态(决定日期方块的颜色)。 */
74
+ const workStatus = computed<YsCalendarStatus | "">(() =>
75
+ covered.value && info.value ? info.value.kind : "",
76
+ );
77
+
78
+ /** 离今天:今天、明天、昨天、N 天后、N 天前。 */
79
+ const relative = computed(() => {
80
+ const today = props.today || ysToday();
81
+ if (!valid.value) return "";
82
+ const diff = ysDaysBetween(today, props.date);
83
+ if (diff === 0) return "今天";
84
+ if (diff === 1) return "明天";
85
+ if (diff === -1) return "昨天";
86
+ if (diff === 2) return "后天";
87
+ if (diff === -2) return "前天";
88
+ return diff > 0 ? `${diff} 天后` : `${-diff} 天前`;
89
+ });
90
+
91
+ const lunarText = computed(() => {
92
+ const lunar = detail.value.lunar;
93
+ if (!lunar) return "";
94
+ return `农历${lunar.monthName}${lunar.dayName} · ${lunar.yearName}${lunar.zodiac}年`;
95
+ });
96
+ /** 传统节日、节气小标签(法定假日名已经在状态标签里,不重复)。 */
97
+ const festivals = computed(() => {
98
+ const list: { text: string; kind: "lunar" | "term" }[] = [];
99
+ const lunar = detail.value.lunar;
100
+ const legal = covered.value ? (info.value?.name ?? "") : "";
101
+ if (lunar?.festival && lunar.festival !== legal)
102
+ list.push({ text: lunar.festival, kind: "lunar" });
103
+ if (lunar?.term) list.push({ text: lunar.term, kind: "term" });
104
+ return list;
105
+ });
106
+ /** 状态标签:工作状态 + 交易状态 + 关键交易日。 */
107
+ const chips = computed(() => {
108
+ const list: { text: string; tone: string; solid?: boolean }[] = [];
109
+ if (!covered.value || !info.value) return list;
110
+ const labels = labelText.value;
111
+ const kind = info.value.kind;
112
+ const name = info.value.name;
113
+ if (kind === "adjusted")
114
+ list.push({
115
+ text: name ? `${labels.adjusted} · ${name}调休` : labels.adjusted,
116
+ tone: "workday",
117
+ solid: true,
118
+ });
119
+ else if (kind === "holiday")
120
+ list.push({
121
+ text: name ? `${labels.holiday} · ${name}` : labels.holiday,
122
+ tone: "holiday",
123
+ });
124
+ else list.push({ text: labels[kind], tone: kind });
125
+ if (props.trading) {
126
+ list.push(
127
+ info.value.trading
128
+ ? { text: labels.trading, tone: "trading" }
129
+ : { text: labels.closed, tone: "closed" },
130
+ );
131
+ for (const tag of detail.value.tags)
132
+ list.push({ text: YS_TRADING_TAG_LABELS[tag].full, tone: "key" });
133
+ }
134
+ return list;
135
+ });
136
+
137
+ /** 本月位置:第几个工作日、第几个交易日、假期第几天。 */
138
+ const positions = computed(() => {
139
+ const list: { label: string; index: number; total: number; tone: string }[] =
140
+ [];
141
+ const { workday, trading, holiday } = detail.value;
142
+ const month = `${monthNumber.value} 月`;
143
+ if (holiday)
144
+ list.push({
145
+ label: `${holiday.name}假期第 ${holiday.index} 天`,
146
+ index: holiday.index,
147
+ total: holiday.total,
148
+ tone: "holiday",
149
+ });
150
+ if (workday)
151
+ list.push({
152
+ label: `${month}第 ${workday.index} 个工作日`,
153
+ index: workday.index,
154
+ total: workday.total,
155
+ tone: "workday",
156
+ });
157
+ if (trading && props.trading)
158
+ list.push({
159
+ label: `${month}第 ${trading.index} 个交易日`,
160
+ index: trading.index,
161
+ total: trading.total,
162
+ tone: "trading",
163
+ });
164
+ return list;
165
+ });
166
+
167
+ /** 补充说明:法定补班不开市、没有放假安排、这个月信息不全。 */
168
+ const note = computed(() => {
169
+ if (!valid.value) return "";
170
+ if (info.value?.covered === false)
171
+ return `${props.date.slice(0, 4)} 年的放假安排还没有(国务院办公厅一般在上一年 10–11 月发布),暂不判断工作日和交易日。`;
172
+ if (!info.value) return "";
173
+ if (props.trading && info.value.kind === "adjusted")
174
+ return "法定补班的周末要上班,但交易所照常休市,不是交易日。";
175
+ return "";
176
+ });
177
+
178
+ const dayEvents = computed(() =>
179
+ props.events.filter((item) => item.date === props.date),
180
+ );
181
+ </script>
182
+
183
+ <template>
184
+ <section
185
+ class="ys-day-card"
186
+ :class="workStatus ? `is-${workStatus}` : ''"
187
+ aria-live="polite"
188
+ >
189
+ <template v-if="valid">
190
+ <header class="ys-day-card__head">
191
+ <div
192
+ class="ys-day-card__tile"
193
+ :class="{ 'is-today': relative === '今天' }"
194
+ >
195
+ <span class="ys-day-card__tile-month">{{ monthNumber }} 月</span>
196
+ <strong class="ys-day-card__tile-day">{{ dayNumber }}</strong>
197
+ <span class="ys-day-card__tile-week">{{ ysWeekdayLabel(date) }}</span>
198
+ </div>
199
+ <div class="ys-day-card__titles">
200
+ <div class="ys-day-card__title">
201
+ <span>{{ ysDateTitle(date) }}</span>
202
+ <span
203
+ class="ys-day-card__relative"
204
+ :class="{ 'is-today': relative === '今天' }"
205
+ >{{ relative }}</span
206
+ >
207
+ </div>
208
+ <div v-if="lunarText" class="ys-day-card__lunar">{{ lunarText }}</div>
209
+ <div v-if="festivals.length" class="ys-day-card__festivals">
210
+ <span
211
+ v-for="item in festivals"
212
+ :key="item.text"
213
+ class="ys-day-card__festival"
214
+ :class="`is-${item.kind}`"
215
+ >{{ item.text }}</span
216
+ >
217
+ </div>
218
+ </div>
219
+ </header>
220
+
221
+ <div v-if="chips.length" class="ys-day-card__chips">
222
+ <span
223
+ v-for="chip in chips"
224
+ :key="chip.text"
225
+ class="ys-day-card__chip"
226
+ :class="[`is-${chip.tone}`, { 'is-solid': chip.solid }]"
227
+ >{{ chip.text }}</span
228
+ >
229
+ </div>
230
+
231
+ <ul v-if="positions.length" class="ys-day-card__positions">
232
+ <li
233
+ v-for="item in positions"
234
+ :key="item.label"
235
+ :class="`is-${item.tone}`"
236
+ >
237
+ <div class="ys-day-card__position-text">
238
+ <span>{{ item.label }}</span>
239
+ <span class="ys-day-card__position-total"
240
+ >共 {{ item.total }}
241
+ {{ item.tone === "holiday" ? "天" : "个" }}</span
242
+ >
243
+ </div>
244
+ <div
245
+ class="ys-day-card__bar"
246
+ role="progressbar"
247
+ :aria-valuenow="item.index"
248
+ :aria-valuemin="1"
249
+ :aria-valuemax="item.total"
250
+ :aria-label="item.label"
251
+ >
252
+ <i :style="{ width: `${(item.index / item.total) * 100}%` }" />
253
+ </div>
254
+ </li>
255
+ </ul>
256
+
257
+ <p v-if="note" class="ys-day-card__note">{{ note }}</p>
258
+
259
+ <div v-if="dayEvents.length" class="ys-day-card__events">
260
+ <div class="ys-day-card__section-title">
261
+ 事项 <strong>{{ dayEvents.length }}</strong>
262
+ </div>
263
+ <ul>
264
+ <li
265
+ v-for="item in dayEvents"
266
+ :key="item.id ?? item.title"
267
+ :class="`is-${item.tone ?? 'primary'}`"
268
+ >
269
+ {{ item.title }}
270
+ </li>
271
+ </ul>
272
+ </div>
273
+
274
+ <div v-if="$slots.default" class="ys-day-card__extra">
275
+ <slot :detail="detail" />
276
+ </div>
277
+ </template>
278
+ <p v-else class="ys-day-card__empty">
279
+ 点月历里的一天,这里显示当天的详情。
280
+ </p>
281
+ </section>
282
+ </template>
283
+
284
+ <style scoped>
285
+ .ys-day-card {
286
+ --tone: var(--ys-color-text-3);
287
+ --tile-bg: color-mix(
288
+ in srgb,
289
+ var(--ys-color-text-3) 8%,
290
+ var(--ys-color-bg-elevated)
291
+ );
292
+ --open-bg: color-mix(
293
+ in srgb,
294
+ var(--ys-color-success) 8%,
295
+ var(--ys-color-bg-elevated)
296
+ );
297
+ --holiday-bg: color-mix(
298
+ in srgb,
299
+ var(--ys-color-warning) 8%,
300
+ var(--ys-color-bg-elevated)
301
+ );
302
+ display: flex;
303
+ flex-direction: column;
304
+ gap: 12px;
305
+ padding: 16px;
306
+ border: 1px solid var(--ys-color-border);
307
+ border-radius: var(--ys-radius-m);
308
+ background: var(--ys-color-bg-elevated);
309
+ }
310
+ /* 和月历同一套底色:固定亮度和饱和度,不发灰也不刺眼 */
311
+ @supports (color: oklch(from red l c h)) {
312
+ .ys-day-card {
313
+ --open-bg: oklch(from var(--ys-color-success) 0.965 0.03 h);
314
+ --holiday-bg: oklch(from var(--ys-color-warning) 0.965 0.032 h);
315
+ }
316
+ html[data-theme="dark"] .ys-day-card {
317
+ --open-bg: oklch(from var(--ys-color-success) 0.28 0.04 h);
318
+ --holiday-bg: oklch(from var(--ys-color-warning) 0.28 0.04 h);
319
+ }
320
+ }
321
+ .ys-day-card.is-workday,
322
+ .ys-day-card.is-adjusted {
323
+ --tone: var(--ys-color-success);
324
+ --tile-bg: var(--open-bg);
325
+ }
326
+ .ys-day-card.is-holiday {
327
+ --tone: var(--ys-color-warning);
328
+ --tile-bg: var(--holiday-bg);
329
+ }
330
+
331
+ /* 头部:日期方块 + 标题 */
332
+ .ys-day-card__head {
333
+ display: flex;
334
+ gap: 14px;
335
+ align-items: center;
336
+ }
337
+ .ys-day-card__tile {
338
+ display: flex;
339
+ flex: none;
340
+ flex-direction: column;
341
+ align-items: center;
342
+ justify-content: center;
343
+ width: 68px;
344
+ height: 76px;
345
+ border: 1px solid color-mix(in srgb, var(--tone) 30%, transparent);
346
+ border-radius: var(--ys-radius-m);
347
+ color: color-mix(in srgb, var(--tone) 85%, var(--ys-color-text-1));
348
+ background: var(--tile-bg);
349
+ line-height: 1.1;
350
+ }
351
+ .ys-day-card__tile.is-today {
352
+ border-color: var(--ys-color-primary);
353
+ box-shadow: 0 0 0 1px var(--ys-color-primary);
354
+ }
355
+ .ys-day-card__tile-month,
356
+ .ys-day-card__tile-week {
357
+ font-size: 12px;
358
+ }
359
+ .ys-day-card__tile-day {
360
+ margin: 2px 0;
361
+ font-size: 30px;
362
+ font-variant-numeric: tabular-nums;
363
+ font-weight: 700;
364
+ }
365
+ .ys-day-card__titles {
366
+ display: flex;
367
+ flex-direction: column;
368
+ gap: 5px;
369
+ min-width: 0;
370
+ }
371
+ .ys-day-card__title {
372
+ display: flex;
373
+ flex-wrap: wrap;
374
+ gap: 4px 8px;
375
+ align-items: baseline;
376
+ color: var(--ys-color-text-1);
377
+ font-size: 15px;
378
+ font-weight: 600;
379
+ }
380
+ .ys-day-card__relative {
381
+ padding: 0 6px;
382
+ border-radius: 999px;
383
+ color: var(--ys-color-text-2);
384
+ background: color-mix(in srgb, var(--ys-color-text-3) 12%, transparent);
385
+ font-size: 12px;
386
+ font-weight: 500;
387
+ line-height: 18px;
388
+ }
389
+ .ys-day-card__relative.is-today {
390
+ color: var(--ys-color-on-solid);
391
+ background: var(--ys-color-primary);
392
+ }
393
+ .ys-day-card__lunar {
394
+ color: var(--ys-color-text-2);
395
+ font-size: 13px;
396
+ }
397
+ .ys-day-card__festivals {
398
+ display: flex;
399
+ flex-wrap: wrap;
400
+ gap: 4px;
401
+ }
402
+ .ys-day-card__festival {
403
+ --chip: var(--ys-color-danger);
404
+ padding: 0 6px;
405
+ border-radius: var(--ys-radius-s);
406
+ color: color-mix(in srgb, var(--chip) 85%, var(--ys-color-text-1));
407
+ background: color-mix(in srgb, var(--chip) 10%, transparent);
408
+ font-size: 12px;
409
+ line-height: 18px;
410
+ }
411
+ .ys-day-card__festival.is-term {
412
+ --chip: var(--ys-color-success);
413
+ }
414
+
415
+ /* 状态标签:和月历格子里的标签同一套颜色 */
416
+ .ys-day-card__chips {
417
+ display: flex;
418
+ flex-wrap: wrap;
419
+ gap: 6px;
420
+ }
421
+ .ys-day-card__chip {
422
+ --chip: var(--ys-color-text-3);
423
+ padding: 1px 8px;
424
+ border: 1px solid color-mix(in srgb, var(--chip) 55%, transparent);
425
+ border-radius: var(--ys-radius-s);
426
+ color: color-mix(in srgb, var(--chip) 88%, var(--ys-color-text-1));
427
+ background: var(--ys-color-bg-elevated);
428
+ font-size: 12px;
429
+ font-weight: 600;
430
+ line-height: 18px;
431
+ }
432
+ .ys-day-card__chip.is-workday {
433
+ --chip: var(--ys-color-success);
434
+ }
435
+ .ys-day-card__chip.is-holiday,
436
+ .ys-day-card__chip.is-key {
437
+ --chip: var(--ys-color-warning);
438
+ }
439
+ .ys-day-card__chip.is-trading {
440
+ --chip: var(--ys-color-primary);
441
+ }
442
+ .ys-day-card__chip.is-weekend,
443
+ .ys-day-card__chip.is-closed {
444
+ border-color: transparent;
445
+ color: var(--ys-color-text-2);
446
+ background: color-mix(in srgb, var(--ys-color-text-3) 14%, transparent);
447
+ }
448
+ .ys-day-card__chip.is-solid {
449
+ border-color: var(--chip);
450
+ color: var(--ys-color-on-solid);
451
+ background: var(--chip);
452
+ }
453
+
454
+ /* 本月位置:文字 + 细进度条 */
455
+ .ys-day-card__positions {
456
+ display: flex;
457
+ flex-direction: column;
458
+ gap: 10px;
459
+ margin: 0;
460
+ padding: 12px 0 0;
461
+ border-top: 1px dashed var(--ys-color-border);
462
+ list-style: none;
463
+ }
464
+ .ys-day-card__positions li {
465
+ --bar: var(--ys-color-success);
466
+ }
467
+ .ys-day-card__positions li.is-trading {
468
+ --bar: var(--ys-color-primary);
469
+ }
470
+ .ys-day-card__positions li.is-holiday {
471
+ --bar: var(--ys-color-warning);
472
+ }
473
+ .ys-day-card__position-text {
474
+ display: flex;
475
+ justify-content: space-between;
476
+ margin-bottom: 4px;
477
+ color: var(--ys-color-text-1);
478
+ font-size: 13px;
479
+ font-weight: 500;
480
+ }
481
+ .ys-day-card__position-total {
482
+ color: var(--ys-color-text-3);
483
+ font-size: 12px;
484
+ font-weight: 400;
485
+ }
486
+ .ys-day-card__bar {
487
+ height: 4px;
488
+ border-radius: 999px;
489
+ overflow: hidden;
490
+ background: color-mix(in srgb, var(--bar) 14%, transparent);
491
+ }
492
+ .ys-day-card__bar i {
493
+ display: block;
494
+ height: 100%;
495
+ border-radius: 999px;
496
+ background: var(--bar);
497
+ }
498
+
499
+ .ys-day-card__note {
500
+ margin: 0;
501
+ padding: 6px 10px;
502
+ border-radius: var(--ys-radius-s);
503
+ color: var(--ys-color-text-2);
504
+ background: color-mix(in srgb, var(--ys-color-warning) 8%, transparent);
505
+ font-size: 12px;
506
+ line-height: 1.6;
507
+ }
508
+ .ys-day-card__section-title {
509
+ margin-bottom: 6px;
510
+ color: var(--ys-color-text-2);
511
+ font-size: 12px;
512
+ }
513
+ .ys-day-card__events ul {
514
+ display: flex;
515
+ flex-direction: column;
516
+ gap: 4px;
517
+ margin: 0;
518
+ padding: 0;
519
+ list-style: none;
520
+ }
521
+ .ys-day-card__events li {
522
+ --chip: var(--ys-color-primary);
523
+ overflow: hidden;
524
+ padding: 3px 8px;
525
+ border-left: 3px solid var(--chip);
526
+ border-radius: var(--ys-radius-s);
527
+ color: var(--ys-color-text-1);
528
+ background: color-mix(in srgb, var(--chip) 8%, transparent);
529
+ font-size: 12px;
530
+ white-space: nowrap;
531
+ text-overflow: ellipsis;
532
+ }
533
+ .ys-day-card__events li.is-success {
534
+ --chip: var(--ys-color-success);
535
+ }
536
+ .ys-day-card__events li.is-warning {
537
+ --chip: var(--ys-color-warning);
538
+ }
539
+ .ys-day-card__events li.is-danger {
540
+ --chip: var(--ys-color-danger);
541
+ }
542
+ .ys-day-card__events li.is-info {
543
+ --chip: var(--ys-color-text-3);
544
+ }
545
+ .ys-day-card__extra {
546
+ padding-top: 12px;
547
+ border-top: 1px dashed var(--ys-color-border);
548
+ }
549
+ .ys-day-card__empty {
550
+ margin: 0;
551
+ color: var(--ys-color-text-3);
552
+ font-size: 13px;
553
+ }
554
+ </style>
package/src/index.ts CHANGED
@@ -4,7 +4,12 @@ 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
6
  export { default as YsCalendar } from "./components/YsCalendar.vue";
7
- export type { YsCalendarEvent } from "./components/YsCalendar.vue";
7
+ export type {
8
+ YsCalendarEvent,
9
+ YsCalendarLabels,
10
+ YsCalendarStatus,
11
+ } from "./components/YsCalendar.vue";
12
+ export { default as YsCalendarDayCard } from "./components/YsCalendarDayCard.vue";
8
13
  export { default as YsTablePagination } from "./components/YsTablePagination.vue";
9
14
  export { default as YsRowActionMenu } from "./components/YsRowActionMenu.vue";
10
15
  export type { YsRowAction } from "./components/YsRowActionMenu.vue";