@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.
@@ -2,24 +2,28 @@
2
2
  /**
3
3
  * 选中日详情卡:放在 YsCalendar 旁边,介绍选中那天的情况。
4
4
  *
5
- * - 头部:日期方块(颜色跟月历一致:工作日、法定补班浅绿,放假浅橙,休息灰)、完整日期、离今天几天、农历、
5
+ * - 头部:日期方块(颜色跟月历一致:上班、法定补班浅绿,放假浅橙,休息灰)、完整日期、离今天几天、农历、
6
6
  * 传统节日和节气。
7
- * - 状态:工作日 / 法定补班 / 休息 / 放假、交易日 / 休市,以及节前最后、节后首日、月初、月末这些关键交易日(全称)。
7
+ * - 状态:上班 / 法定补班 / 休息 / 放假,开市 / 休市 / 交易所休市,当晚有夜盘 / 当晚无夜盘,以及节前最后、节后首日、
8
+ * 月初、月末这些关键交易日(全称)。用语和 YsCalendar 格子一致。
8
9
  * - 本月位置:几月第 N 个工作日、第 N 个交易日(带进度条),放假时写「国庆节假期第 3 天,共 8 天」。
9
10
  * - 当天的事项(events),以及默认插槽放页面自己的内容(如上一个、下一个交易日和 T+N 推算)。
10
11
  * - 农历、干支生肖、传统节日和节气默认显示,页面不用加开关;确实不需要的系统传 :lunar="false"。农历用 ysLunar 现算,只用于显示。
11
- * - 交易所额外休市(国务院安排上班、交易所休市)写「交易所休市」和原因;交易日写当晚有没有期货夜盘、夜盘归属哪个交易日
12
- * (night 关掉不写)。
12
+ * - 交易所额外休市(国务院安排上班、交易所休市)写「交易所休市」和原因;交易日写当晚有没有期货夜盘:有就写计入哪个交易日,
13
+ * 没有就写原因(节前最后一个交易日、nightNote 传入的夜盘例外原因、2013-07-05 以前还没有夜盘),未知写明还没有安排
14
+ * (night 关掉不写)。月历格子只标「夜盘」,没有夜盘的原因都在这里。
13
15
  * - years 传了就在底部写这一天所在年份的数据来源与核对状态。
14
16
  * - 数据都由 @ysgroup/core 的 ysDayDetail 从服务端下发的 days 推出,组件只显示。
15
17
  */
16
18
  import { computed } from "vue";
17
19
  import {
20
+ YS_NIGHT_SESSION_START,
18
21
  YS_TRADING_TAG_LABELS,
19
22
  ysDateTitle,
20
23
  ysDayDetail,
21
24
  ysDaysBetween,
22
25
  ysIsDate,
26
+ ysShortDateTitle,
23
27
  ysToday,
24
28
  ysWeekdayLabel,
25
29
  ysCalendarYearText,
@@ -33,12 +37,13 @@ import type {
33
37
  } from "./YsCalendar.vue";
34
38
 
35
39
  const DEFAULT_LABELS: YsCalendarLabels = {
36
- trading: "交易日",
40
+ trading: "开市",
37
41
  closed: "休市",
38
- workday: "工作日",
42
+ workday: "上班",
39
43
  adjusted: "法定补班",
40
44
  weekend: "休息",
41
45
  holiday: "放假",
46
+ night: "夜盘",
42
47
  };
43
48
 
44
49
  const props = withDefaults(
@@ -57,6 +62,8 @@ const props = withDefaults(
57
62
  lunar?: boolean;
58
63
  /** 交易日写当晚有没有期货夜盘(trading 关掉时也不写)。 */
59
64
  night?: boolean;
65
+ /** 这一天的夜盘例外原因(如「疫情期间暂停夜盘」);有就写在当晚无夜盘的说明里。 */
66
+ nightNote?: string;
60
67
  /** 各年数据来源与核对状态(服务端 CalendarService.year_states())。 */
61
68
  years?: readonly YsCalendarYearInfo[];
62
69
  }>(),
@@ -68,6 +75,7 @@ const props = withDefaults(
68
75
  trading: true,
69
76
  lunar: true,
70
77
  night: true,
78
+ nightNote: "",
71
79
  years: () => [],
72
80
  },
73
81
  );
@@ -138,19 +146,23 @@ const chips = computed(() => {
138
146
  });
139
147
  else list.push({ text: labels[kind], tone: kind });
140
148
  if (info.value.market_closed)
141
- list.push({ text: "交易所休市", tone: "holiday" });
142
- if (props.trading) {
149
+ list.push({ text: "交易所休市", tone: "closed" });
150
+ else if (props.trading)
143
151
  list.push(
144
152
  info.value.trading
145
153
  ? { text: labels.trading, tone: "trading" }
146
154
  : { text: labels.closed, tone: "closed" },
147
155
  );
148
- if (props.night && info.value.trading && info.value.night_session != null)
149
- list.push(
150
- info.value.night_session
151
- ? { text: "当晚有夜盘", tone: "trading" }
152
- : { text: "当晚无夜盘", tone: "key" },
153
- );
156
+ if (props.trading) {
157
+ if (props.night && info.value.trading && info.value.night_session === true)
158
+ list.push({ text: `当晚有${labels.night}`, tone: "night", solid: true });
159
+ else if (
160
+ props.night &&
161
+ info.value.trading &&
162
+ info.value.night_session === false &&
163
+ props.date >= YS_NIGHT_SESSION_START
164
+ )
165
+ list.push({ text: `当晚无${labels.night}`, tone: "closed" });
154
166
  for (const tag of detail.value.tags)
155
167
  list.push({ text: YS_TRADING_TAG_LABELS[tag].full, tone: "key" });
156
168
  }
@@ -165,21 +177,21 @@ const positions = computed(() => {
165
177
  const month = `${monthNumber.value} 月`;
166
178
  if (holiday)
167
179
  list.push({
168
- label: `${holiday.name}假期第 ${holiday.index} 天`,
180
+ label: `${holiday.name}假期 第 ${holiday.index} 天`,
169
181
  index: holiday.index,
170
182
  total: holiday.total,
171
183
  tone: "holiday",
172
184
  });
173
185
  if (workday)
174
186
  list.push({
175
- label: `${month}第 ${workday.index} 个工作日`,
187
+ label: `${month} 第 ${workday.index} 个工作日`,
176
188
  index: workday.index,
177
189
  total: workday.total,
178
190
  tone: "workday",
179
191
  });
180
192
  if (trading && props.trading)
181
193
  list.push({
182
- label: `${month}第 ${trading.index} 个交易日`,
194
+ label: `${month} 第 ${trading.index} 个交易日`,
183
195
  index: trading.index,
184
196
  total: trading.total,
185
197
  tone: "trading",
@@ -187,31 +199,41 @@ const positions = computed(() => {
187
199
  return list;
188
200
  });
189
201
 
190
- /** 补充说明:法定补班不开市、没有放假安排、这个月信息不全。 */
191
- const note = computed(() => {
192
- if (!valid.value) return "";
193
- if (info.value?.covered === false)
194
- return `${props.date.slice(0, 4)} 年的放假安排还没有(国务院办公厅一般在上一年 10–11 月发布),暂不判断工作日和交易日。`;
195
- if (!info.value) return "";
196
- if (props.trading && info.value.kind === "adjusted")
197
- return "法定补班的周末要上班,但交易所照常休市,不是交易日。";
198
- if (info.value.market_closed)
199
- return `国务院安排这天上班,但交易所休市:${info.value.market_closed}。`;
200
- if (
201
- props.trading &&
202
- props.night &&
203
- info.value.night_session &&
204
- info.value.night_trading_day
205
- )
206
- return `当晚 21:00 起的夜盘归属 ${info.value.night_trading_day} 交易日。`;
207
- if (
208
- props.trading &&
209
- props.night &&
210
- info.value.trading &&
211
- info.value.night_session === null
212
- )
213
- return "下一个交易日所在年份还没有安排,暂不判断当晚有没有夜盘。";
214
- return "";
202
+ /** 补充说明:法定补班不开市、交易所休市原因、没有放假安排、当晚夜盘计入哪天或为什么没有。 */
203
+ const notes = computed(() => {
204
+ const list: string[] = [];
205
+ if (!valid.value) return list;
206
+ if (info.value?.covered === false) {
207
+ list.push(
208
+ `${props.date.slice(0, 4)} 年的放假安排还没有(国务院办公厅一般在上一年 10–11 月发布),暂不判断工作日和交易日。`,
209
+ );
210
+ return list;
211
+ }
212
+ const item = info.value;
213
+ if (!item) return list;
214
+ if (props.trading && item.kind === "adjusted")
215
+ list.push("法定补班的周末要上班,但交易所照常休市,不开市。");
216
+ if (item.market_closed)
217
+ list.push(`国务院安排这天上班,但交易所休市:${item.market_closed}。`);
218
+ if (!props.trading || !props.night || !item.trading) return list;
219
+ if (item.night_session === true)
220
+ list.push(
221
+ item.night_trading_day
222
+ ? `当晚 21:00 起有期货夜盘,计入 ${ysShortDateTitle(item.night_trading_day)} 交易日。`
223
+ : "当晚 21:00 起有期货夜盘。",
224
+ );
225
+ else if (item.night_session === null)
226
+ list.push("下一个交易日所在年份还没有安排,暂不判断当晚有没有夜盘。");
227
+ else if (item.night_session === false) {
228
+ if (props.date < YS_NIGHT_SESSION_START)
229
+ list.push("2013 年 7 月 5 日起才有期货夜盘,这一天还没有夜盘。");
230
+ else if (props.nightNote)
231
+ list.push(`当晚没有夜盘:${props.nightNote}。`);
232
+ else if (detail.value.tags.includes("pre-holiday"))
233
+ list.push("节前最后一个交易日,当晚没有夜盘。");
234
+ // 其余情况(这一屏看不到下一个交易日、夜盘例外又没传原因)不猜原因,状态标签里已经写了「当晚无夜盘」
235
+ }
236
+ return list;
215
237
  });
216
238
 
217
239
  const yearInfo = computed(() =>
@@ -271,6 +293,18 @@ const dayEvents = computed(() =>
271
293
  >{{ chip.text }}</span
272
294
  >
273
295
  </div>
296
+ <div
297
+ v-if="detail.tags.length && trading"
298
+ class="ys-day-card__tags"
299
+ aria-label="关键交易日"
300
+ >
301
+ <span
302
+ v-for="tag in detail.tags"
303
+ :key="tag"
304
+ class="ys-day-card__tag"
305
+ >{{ YS_TRADING_TAG_LABELS[tag].full }}</span
306
+ >
307
+ </div>
274
308
 
275
309
  <ul v-if="positions.length" class="ys-day-card__positions">
276
310
  <li
@@ -280,8 +314,8 @@ const dayEvents = computed(() =>
280
314
  >
281
315
  <div class="ys-day-card__position-text">
282
316
  <span>{{ item.label }}</span>
283
- <span class="ys-day-card__position-total"
284
- >共 {{ item.total }}
317
+ <span class="ys-day-card__position-count"
318
+ >{{ item.index }} / {{ item.total }}
285
319
  {{ item.tone === "holiday" ? "天" : "个" }}</span
286
320
  >
287
321
  </div>
@@ -298,7 +332,9 @@ const dayEvents = computed(() =>
298
332
  </li>
299
333
  </ul>
300
334
 
301
- <p v-if="note" class="ys-day-card__note">{{ note }}</p>
335
+ <p v-for="text in notes" :key="text" class="ys-day-card__note">
336
+ {{ text }}
337
+ </p>
302
338
 
303
339
  <div v-if="dayEvents.length" class="ys-day-card__events">
304
340
  <div class="ys-day-card__section-title">
@@ -466,6 +502,20 @@ const dayEvents = computed(() =>
466
502
  flex-wrap: wrap;
467
503
  gap: 6px;
468
504
  }
505
+ .ys-day-card__tags {
506
+ display: flex;
507
+ flex-wrap: wrap;
508
+ gap: 5px;
509
+ }
510
+ .ys-day-card__tag {
511
+ padding: 1px 8px;
512
+ border-radius: var(--ys-radius-s);
513
+ color: color-mix(in srgb, var(--ys-color-warning) 85%, var(--ys-color-text-1));
514
+ background: color-mix(in srgb, var(--ys-color-warning) 10%, transparent);
515
+ font-size: 11px;
516
+ font-weight: 600;
517
+ line-height: 18px;
518
+ }
469
519
  .ys-day-card__chip {
470
520
  --chip: var(--ys-color-text-3);
471
521
  padding: 1px 8px;
@@ -486,6 +536,14 @@ const dayEvents = computed(() =>
486
536
  }
487
537
  .ys-day-card__chip.is-trading {
488
538
  --chip: var(--ys-color-primary);
539
+ background: var(--ys-color-primary-soft);
540
+ }
541
+ /* 夜盘和月历格子同一个靛紫 */
542
+ .ys-day-card__chip.is-night {
543
+ --chip: #5b4bd6;
544
+ }
545
+ html[data-theme="dark"] .ys-day-card__chip.is-night {
546
+ --chip: #a597ff;
489
547
  }
490
548
  .ys-day-card__chip.is-weekend,
491
549
  .ys-day-card__chip.is-closed {
@@ -526,7 +584,11 @@ const dayEvents = computed(() =>
526
584
  font-size: 13px;
527
585
  font-weight: 500;
528
586
  }
529
- .ys-day-card__position-total {
587
+ .ys-day-card__position-text > span:first-child {
588
+ letter-spacing: 0.03em;
589
+ font-variant-numeric: tabular-nums;
590
+ }
591
+ .ys-day-card__position-count {
530
592
  color: var(--ys-color-text-3);
531
593
  font-size: 12px;
532
594
  font-weight: 400;
@@ -0,0 +1,43 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 处理状态标签:消息的「处理状态」与未读、已读互相独立。
4
+ * - pending 待处理:红色,计入数字角标;
5
+ * - done 已处理:灰色,不必再关注;
6
+ * - none 纯通知:不显示,只有未读、已读。
7
+ */
8
+ import { computed } from "vue";
9
+
10
+ export type YsHandleState = "none" | "pending" | "done";
11
+
12
+ const props = withDefaults(defineProps<{ state?: YsHandleState | string | null }>(), { state: "none" });
13
+
14
+ const label = computed(() => (props.state === "pending" ? "待处理" : props.state === "done" ? "已处理" : ""));
15
+ </script>
16
+
17
+ <template>
18
+ <span v-if="label" class="ys-handle-tag" :class="`is-${state}`">{{ label }}</span>
19
+ </template>
20
+
21
+ <style scoped>
22
+ .ys-handle-tag {
23
+ display: inline-flex;
24
+ flex: none;
25
+ align-items: center;
26
+ padding: 0 6px;
27
+ border: 1px solid transparent;
28
+ border-radius: var(--ys-radius-s);
29
+ font-size: 12px;
30
+ font-weight: 600;
31
+ line-height: 18px;
32
+ white-space: nowrap;
33
+ }
34
+ .ys-handle-tag.is-pending {
35
+ border-color: color-mix(in srgb, var(--ys-color-danger) 45%, transparent);
36
+ color: var(--ys-color-danger);
37
+ background: color-mix(in srgb, var(--ys-color-danger) 10%, transparent);
38
+ }
39
+ .ys-handle-tag.is-done {
40
+ color: var(--ys-color-text-3);
41
+ background: color-mix(in srgb, var(--ys-color-text-3) 12%, transparent);
42
+ }
43
+ </style>
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export { default as YsCalendar } from "./components/YsCalendar.vue";
7
7
  export type {
8
8
  YsCalendarEvent,
9
9
  YsCalendarLabels,
10
+ YsCalendarLegendKey,
10
11
  YsCalendarStatus,
11
12
  } from "./components/YsCalendar.vue";
12
13
  export { default as YsCalendarDayCard } from "./components/YsCalendarDayCard.vue";
@@ -56,6 +57,18 @@ export { ysMultiItems, ysMultiText, YS_MULTI_SEPARATOR } from "./multiValue";
56
57
  export { default as YsBoolMark } from "./components/YsBoolMark.vue";
57
58
  export { default as YsSegmented } from "./components/YsSegmented.vue";
58
59
  export { default as YsCountBadge } from "./components/YsCountBadge.vue";
60
+ export { default as YsHandleTag } from "./components/YsHandleTag.vue";
61
+ export type { YsHandleState } from "./components/YsHandleTag.vue";
62
+ export {
63
+ groupYsPendingNotices,
64
+ queueYsPending,
65
+ setYsPendingPopup,
66
+ showYsPending,
67
+ ysPendingLoginSummary,
68
+ ysPendingPopupOn,
69
+ ysTopNotification,
70
+ } from "./pendingNotice";
71
+ export type { YsPendingNotice } from "./pendingNotice";
59
72
  export { default as YsFilePreview } from "./components/YsFilePreview.vue";
60
73
  // 文件规范:上传队列、拖入与粘贴、文件标签(服务端规则在 ys_base.media)。
61
74
  export { default as YsFileNotes } from "./components/YsFileNotes.vue";
@@ -0,0 +1,133 @@
1
+ /**
2
+ * 右上角待处理提示(全平台统一,来自 Auth 的 todo_notice 做法):
3
+ * - 服务端只推标题、摘要和跳转链接,不带敏感正文;
4
+ * - 1.5 秒内到达的同类提示合成一张(groupYsPendingNotices,纯函数);
5
+ * - 同一账号开了几个标签页时,只在正在看的那个弹(BroadcastChannel 认领);
6
+ * - 带「去处理」「稍后」;警示图标用 --ys-color-attention(橙黄),不用 warning(偏棕黄);
7
+ * - 「新事项弹出提示」开关存本机浏览器,各系统的设置页调用 setYsPendingPopup。
8
+ */
9
+ import { h, ref } from "vue";
10
+ import { ElButton, ElNotification, type NotificationOptions } from "element-plus";
11
+
12
+ /** 由公共外壳提供实际顶栏位置,兼容移动端安全区。 */
13
+ export function ysTopNotification(options: NotificationOptions) {
14
+ const top = typeof document === "undefined" ? 0 : (document.querySelector(".ys-layout__top")?.getBoundingClientRect().bottom ?? 0);
15
+ return ElNotification({ ...options, position: "top-right", offset: Math.max(0, Math.ceil(top)) });
16
+ }
17
+
18
+ export interface YsPendingNotice {
19
+ kind: string;
20
+ title: string;
21
+ summary?: string;
22
+ link: string;
23
+ }
24
+
25
+ const STORAGE_KEY = "ys-pending-popup";
26
+ const MERGE_MS = 1500;
27
+ const CLAIM_MS = 5000;
28
+
29
+ function readOn(): boolean {
30
+ try {
31
+ return localStorage.getItem(STORAGE_KEY) !== "off";
32
+ } catch {
33
+ return true;
34
+ }
35
+ }
36
+
37
+ /** 是否弹出待处理提示(本机浏览器设置,默认开)。 */
38
+ export const ysPendingPopupOn = ref(readOn());
39
+
40
+ export function setYsPendingPopup(on: boolean): void {
41
+ ysPendingPopupOn.value = on;
42
+ try {
43
+ localStorage.setItem(STORAGE_KEY, on ? "on" : "off");
44
+ } catch {
45
+ /* 存不下不影响本次使用 */
46
+ }
47
+ }
48
+
49
+ /** 短时间内到达的提示按 kind 分组:一组只有一条原样弹,多条合成「标题等 N 件」。 */
50
+ export function groupYsPendingNotices(items: YsPendingNotice[]): YsPendingNotice[] {
51
+ const groups = new Map<string, YsPendingNotice[]>();
52
+ for (const item of items) {
53
+ const list = groups.get(item.kind) ?? [];
54
+ list.push(item);
55
+ groups.set(item.kind, list);
56
+ }
57
+ return [...groups.values()].map((list) => {
58
+ const first = list[0]!;
59
+ if (list.length === 1) return first;
60
+ return { kind: first.kind, title: `${first.title}等 ${list.length} 件`, summary: "点「去处理」一并查看", link: first.link };
61
+ });
62
+ }
63
+
64
+ const channel = typeof BroadcastChannel === "undefined" ? null : new BroadcastChannel("ys-pending-notice");
65
+ const claimed = new Map<string, number>();
66
+ channel?.addEventListener("message", (event) => {
67
+ const key = String((event.data as { key?: string })?.key ?? "");
68
+ if (key) claimed.set(key, Date.now());
69
+ });
70
+
71
+ function claim(key: string): boolean {
72
+ const at = claimed.get(key);
73
+ if (at && Date.now() - at < CLAIM_MS) return false;
74
+ claimed.set(key, Date.now());
75
+ channel?.postMessage({ key });
76
+ return true;
77
+ }
78
+
79
+ function warnIcon() {
80
+ return h("svg", { viewBox: "0 0 24 24", width: 20, height: 20, "aria-hidden": "true", style: "color: var(--ys-color-attention)" }, [
81
+ h("path", { fill: "currentColor", d: "M12 2 1 21h22L12 2zm1 15h-2v-2h2v2zm0-4h-2V9h2v4z" }),
82
+ ]);
83
+ }
84
+
85
+ /** 立即弹一张;页面不在前台、开关关闭、或别的标签页已经弹了就不弹。go 由各系统传入(通常是 router.push)。 */
86
+ export function showYsPending(go: (link: string) => void, notice: YsPendingNotice): void {
87
+ if (!ysPendingPopupOn.value || document.visibilityState !== "visible") return;
88
+ if (!claim(`${notice.kind}:${notice.title}:${notice.summary ?? ""}`)) return;
89
+ const card = ysTopNotification({
90
+ customClass: "ys-pending-notice",
91
+ icon: warnIcon,
92
+ title: notice.title,
93
+ duration: 0,
94
+ message: h("div", [
95
+ notice.summary ? h("p", { style: "margin: 0 0 8px" }, notice.summary) : null,
96
+ h("div", { style: "display: flex; gap: 8px" }, [
97
+ h(
98
+ ElButton,
99
+ {
100
+ type: "primary",
101
+ size: "small",
102
+ onClick: () => {
103
+ card.close();
104
+ go(notice.link);
105
+ },
106
+ },
107
+ () => "去处理",
108
+ ),
109
+ h(ElButton, { size: "small", onClick: () => card.close() }, () => "稍后"),
110
+ ]),
111
+ ]),
112
+ });
113
+ }
114
+
115
+ let buffer: YsPendingNotice[] = [];
116
+ let timer: ReturnType<typeof setTimeout> | undefined;
117
+
118
+ /** 收到一条提示:攒 1.5 秒再弹,期间同类的合成一张。 */
119
+ export function queueYsPending(go: (link: string) => void, notice: YsPendingNotice): void {
120
+ buffer.push(notice);
121
+ clearTimeout(timer);
122
+ timer = setTimeout(() => {
123
+ const items = groupYsPendingNotices(buffer);
124
+ buffer = [];
125
+ items.forEach((item) => showYsPending(go, item));
126
+ }, MERGE_MS);
127
+ }
128
+
129
+ /** 登录后汇总一次:有待处理时返回一张汇总卡片,没有返回 null。 */
130
+ export function ysPendingLoginSummary(count: number, link: string): YsPendingNotice | null {
131
+ if (!Number.isFinite(count) || count <= 0) return null;
132
+ return { kind: "login", title: `你有 ${count} 件待处理的事`, summary: "点「去处理」查看", link };
133
+ }