@v587d/capital-generation 2.25.0 → 2.27.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.
- package/CHANGELOG.md +69 -0
- package/README.md +8 -6
- package/automation/brief.js +21 -24
- package/automation/builtins.js +55 -54
- package/automation/client.js +11 -3
- package/automation/client.src.cjs +70 -8
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/sources/tencent-http.d.ts +20 -0
- package/lib/sources/tencent-http.js +37 -58
- package/lib/sources/tencent-public-core.d.ts +31 -0
- package/lib/sources/tencent-public-core.js +63 -0
- package/lib/sources/trend-series.d.ts +53 -0
- package/lib/sources/trend-series.js +382 -0
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +2 -1
- package/watchlist/client.js +124 -3
- package/watchlist/client.src.cjs +1229 -1
- package/watchlist/index.js +146 -0
- package/watchlist/package.json +1 -1
package/watchlist/client.src.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* fetches while closed. No turn-tail slot and no custom session events (closed
|
|
6
6
|
* vocabulary, AGENTS.md §7). Only the search debounce is a timer.
|
|
7
7
|
*/
|
|
8
|
-
const { createElement: h, useEffect, useState } = require('react')
|
|
8
|
+
const { createElement: h, useEffect, useRef, useState } = require('react')
|
|
9
9
|
const { createSnapshotStore } = require('@deepseek-ai/dsh-client-store')
|
|
10
10
|
// Official icons only; the set has no wallet/pie/coin glyph, so stepper keys use text −/+.
|
|
11
11
|
// `MenuItemButton` gives the remove row official geometry and its separator line.
|
|
@@ -111,6 +111,74 @@ const zh = {
|
|
|
111
111
|
'partial.a-share': 'A 股检索不可用:',
|
|
112
112
|
'partial.hk': '港股检索不可用:',
|
|
113
113
|
'partial.us': '美股检索不可用:',
|
|
114
|
+
/* 行情工作台(左侧栏入口 + 主面板);只读现有报价,不新增数据源。 */
|
|
115
|
+
'desk.panel': '自选股',
|
|
116
|
+
'desk.title': '自选股行情工作台',
|
|
117
|
+
'desk.refresh': '刷新行情',
|
|
118
|
+
'desk.refreshing': '刷新中…',
|
|
119
|
+
'desk.loading': '正在读取自选股…',
|
|
120
|
+
'desk.lastUpdate': '最近更新',
|
|
121
|
+
'desk.notRefreshed': '未刷新',
|
|
122
|
+
'desk.filter': '筛选标的',
|
|
123
|
+
'desk.filterPlaceholder': '名称或代码',
|
|
124
|
+
'desk.group': '分组',
|
|
125
|
+
'desk.allGroups': '全部',
|
|
126
|
+
'desk.newGroup': '分组名称',
|
|
127
|
+
'desk.createGroup': '新建',
|
|
128
|
+
'desk.deleteGroup': '删除分组',
|
|
129
|
+
'desk.noGroup': '未分组',
|
|
130
|
+
'desk.more': '更多操作',
|
|
131
|
+
'desk.noGroupYet': '还没有分组',
|
|
132
|
+
'desk.pin': '置顶',
|
|
133
|
+
'desk.remove': '移除',
|
|
134
|
+
'desk.removeHint': '再点一次删除按钮确认移除',
|
|
135
|
+
'desk.cancel': '取消',
|
|
136
|
+
'desk.empty': '还没有自选股',
|
|
137
|
+
'desk.emptyHint': '用输入框的「自选股」面板添加标的,这里会同步显示。',
|
|
138
|
+
'desk.noMatch': '没有匹配的标的',
|
|
139
|
+
'desk.noMatchHint': '换个关键词,或切回「全部」分组。',
|
|
140
|
+
'desk.selectHint': '选择一只标的查看详情',
|
|
141
|
+
'desk.selectHintBody': '左侧列表按分组筛选;选中后这里显示报价、分时与成交量。',
|
|
142
|
+
'desk.intraday': '分时',
|
|
143
|
+
'desk.trendLoading': '正在读取分时…',
|
|
144
|
+
'desk.trendUnavailable': '该市场暂时没有分时数据',
|
|
145
|
+
'desk.trendUnavailableHint': '场外美股与部分海外指数没有分时源,这里不画假走势。',
|
|
146
|
+
'desk.trendError': '分时加载失败',
|
|
147
|
+
'desk.trendRetry': '重试',
|
|
148
|
+
'desk.daily': '日K',
|
|
149
|
+
'desk.fold': '收起',
|
|
150
|
+
'desk.unfold': '展开',
|
|
151
|
+
'desk.adjustQfq': '前复权',
|
|
152
|
+
'desk.klineLoading': '正在读取日K…',
|
|
153
|
+
'desk.klineError': '日K暂时取不到',
|
|
154
|
+
'desk.klineUnavailable': '该市场暂时没有日K数据',
|
|
155
|
+
'desk.klineUnavailableHint': '港美股指数只有分时,没有可用的日线序列',
|
|
156
|
+
'desk.kOpen': '开',
|
|
157
|
+
'desk.kHigh': '高',
|
|
158
|
+
'desk.kLow': '低',
|
|
159
|
+
'desk.kClose': '收',
|
|
160
|
+
'desk.trendLive': '盘中',
|
|
161
|
+
'desk.trendClosed': '收盘',
|
|
162
|
+
'desk.trendPrevious': '上一交易日',
|
|
163
|
+
'desk.trendStale': '数据滞后',
|
|
164
|
+
'desk.trendOpen': '今开',
|
|
165
|
+
'desk.trendHigh': '最高',
|
|
166
|
+
'desk.trendLow': '最低',
|
|
167
|
+
'desk.trendAvg': '均价',
|
|
168
|
+
'desk.trendVolume': '成交量',
|
|
169
|
+
'desk.trendAmount': '成交额',
|
|
170
|
+
'desk.lot': '手',
|
|
171
|
+
'desk.share': '股',
|
|
172
|
+
'desk.trendZoneUs': '美东',
|
|
173
|
+
'desk.trendZoneHk': '香港',
|
|
174
|
+
'desk.capturedAt': '行情时间',
|
|
175
|
+
'desk.groupsOf': '所属分组',
|
|
176
|
+
'desk.kind': '标的类型',
|
|
177
|
+
'desk.colName': '名称',
|
|
178
|
+
'desk.colPrice': '最新',
|
|
179
|
+
'desk.colChange': '涨跌',
|
|
180
|
+
'desk.colAction': '操作',
|
|
181
|
+
'desk.loadFailed': '自选股服务暂不可用',
|
|
114
182
|
}
|
|
115
183
|
|
|
116
184
|
const en = {
|
|
@@ -190,6 +258,74 @@ const en = {
|
|
|
190
258
|
'partial.a-share': 'A-share search unavailable: ',
|
|
191
259
|
'partial.hk': 'HK search unavailable: ',
|
|
192
260
|
'partial.us': 'US search unavailable: ',
|
|
261
|
+
/* Market desk (sidebar entry + main panel); reads the existing quotes, no new data source. */
|
|
262
|
+
'desk.panel': 'Watchlist',
|
|
263
|
+
'desk.title': 'Watchlist market desk',
|
|
264
|
+
'desk.refresh': 'Refresh quotes',
|
|
265
|
+
'desk.refreshing': 'Refreshing…',
|
|
266
|
+
'desk.loading': 'Loading watchlist…',
|
|
267
|
+
'desk.lastUpdate': 'Last update',
|
|
268
|
+
'desk.notRefreshed': 'Not refreshed',
|
|
269
|
+
'desk.filter': 'Filter symbols',
|
|
270
|
+
'desk.filterPlaceholder': 'Name or code',
|
|
271
|
+
'desk.group': 'Group',
|
|
272
|
+
'desk.allGroups': 'All',
|
|
273
|
+
'desk.newGroup': 'Group name',
|
|
274
|
+
'desk.createGroup': 'Create',
|
|
275
|
+
'desk.deleteGroup': 'Delete group',
|
|
276
|
+
'desk.noGroup': 'Ungrouped',
|
|
277
|
+
'desk.more': 'More actions',
|
|
278
|
+
'desk.noGroupYet': 'No groups yet',
|
|
279
|
+
'desk.pin': 'Pin',
|
|
280
|
+
'desk.remove': 'Remove',
|
|
281
|
+
'desk.removeHint': 'Press remove again to confirm',
|
|
282
|
+
'desk.cancel': 'Cancel',
|
|
283
|
+
'desk.empty': 'No symbols yet',
|
|
284
|
+
'desk.emptyHint': 'Add symbols from the watchlist panel in the composer; they appear here.',
|
|
285
|
+
'desk.noMatch': 'No symbols match',
|
|
286
|
+
'desk.noMatchHint': 'Try another term, or switch back to All.',
|
|
287
|
+
'desk.selectHint': 'Select a symbol',
|
|
288
|
+
'desk.selectHintBody': 'The left list filters by group; the quote, intraday and volume panels follow the selection.',
|
|
289
|
+
'desk.intraday': 'Intraday',
|
|
290
|
+
'desk.trendLoading': 'Loading intraday…',
|
|
291
|
+
'desk.trendUnavailable': 'No intraday series for this market',
|
|
292
|
+
'desk.trendUnavailableHint': 'OTC US lines and some overseas indices have no intraday source; nothing is drawn to fill the gap.',
|
|
293
|
+
'desk.trendError': 'Intraday failed to load',
|
|
294
|
+
'desk.trendRetry': 'Retry',
|
|
295
|
+
'desk.daily': 'Daily',
|
|
296
|
+
'desk.fold': 'Collapse',
|
|
297
|
+
'desk.unfold': 'Expand',
|
|
298
|
+
'desk.adjustQfq': 'Forward-adjusted',
|
|
299
|
+
'desk.klineLoading': 'Loading daily bars…',
|
|
300
|
+
'desk.klineError': 'Daily bars are unavailable',
|
|
301
|
+
'desk.klineUnavailable': 'No daily bars for this market',
|
|
302
|
+
'desk.klineUnavailableHint': 'HK/US indices carry an intraday series only',
|
|
303
|
+
'desk.kOpen': 'Open',
|
|
304
|
+
'desk.kHigh': 'High',
|
|
305
|
+
'desk.kLow': 'Low',
|
|
306
|
+
'desk.kClose': 'Close',
|
|
307
|
+
'desk.trendLive': 'Live',
|
|
308
|
+
'desk.trendClosed': 'Closed',
|
|
309
|
+
'desk.trendPrevious': 'Previous session',
|
|
310
|
+
'desk.trendStale': 'Stale',
|
|
311
|
+
'desk.trendOpen': 'Open',
|
|
312
|
+
'desk.trendHigh': 'High',
|
|
313
|
+
'desk.trendLow': 'Low',
|
|
314
|
+
'desk.trendAvg': 'VWAP',
|
|
315
|
+
'desk.trendVolume': 'Volume',
|
|
316
|
+
'desk.trendAmount': 'Turnover',
|
|
317
|
+
'desk.lot': 'lots',
|
|
318
|
+
'desk.share': 'shares',
|
|
319
|
+
'desk.trendZoneUs': 'ET',
|
|
320
|
+
'desk.trendZoneHk': 'HK',
|
|
321
|
+
'desk.capturedAt': 'As of',
|
|
322
|
+
'desk.groupsOf': 'Groups',
|
|
323
|
+
'desk.kind': 'Instrument',
|
|
324
|
+
'desk.colName': 'Symbol',
|
|
325
|
+
'desk.colPrice': 'Last',
|
|
326
|
+
'desk.colChange': 'Change',
|
|
327
|
+
'desk.colAction': 'Actions',
|
|
328
|
+
'desk.loadFailed': 'Watchlist service unavailable',
|
|
193
329
|
}
|
|
194
330
|
|
|
195
331
|
/**
|
|
@@ -386,6 +522,127 @@ const CSS = `
|
|
|
386
522
|
.capital-watchlist-rows { width: 256px; }
|
|
387
523
|
/* Theme has no global border-box reset; the official item padding would overflow the list. */
|
|
388
524
|
.capital-watchlist-rows button { box-sizing: border-box; }
|
|
525
|
+
/* --- 行情工作台:左侧栏入口 + main 面板。卡片走发丝线,浮层交给官方 Menu。 --- */
|
|
526
|
+
.cwd-page { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow-y: auto; background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); --cwd-card: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1)); --capital-watchlist-up: #d1493f; --capital-watchlist-down: #17a063; }
|
|
527
|
+
.cwd-inner { display: flex; flex: 1; flex-direction: column; width: 100%; min-height: 0; max-width: 1180px; margin: 0 auto; padding: 24px 32px 32px; }
|
|
528
|
+
.cwd-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
|
|
529
|
+
.cwd-title { margin: 0; font-size: 26px; line-height: 32px; font-weight: 650; letter-spacing: -.2px; }
|
|
530
|
+
.cwd-headactions { display: flex; align-items: center; gap: 14px; flex: none; }
|
|
531
|
+
.cwd-updated { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
532
|
+
.cwd-refresh { display: inline-flex; align-items: center; gap: 6px; flex: none; height: 34px; padding: 0 14px; border: .5px solid color-mix(in srgb, var(--dsw-alias-state-business-primary) 25%, transparent); border-radius: 10px; background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 12%, transparent); color: var(--dsw-alias-state-business-primary); font-family: inherit; font-size: 13px; line-height: 20px; font-weight: 500; cursor: pointer; }
|
|
533
|
+
.cwd-refresh:hover:not(:disabled) { background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 20%, transparent); }
|
|
534
|
+
.cwd-refresh:disabled { opacity: .45; cursor: not-allowed; }
|
|
535
|
+
.cwd-body { display: grid; flex: 1 1 auto; grid-template-columns: minmax(0, 1fr) minmax(430px, 1.35fr); grid-template-rows: minmax(0, 1fr); gap: 22px; align-items: stretch; min-height: 420px; max-height: 880px; }
|
|
536
|
+
/* ⛔ 行高必须钉死:隐式行按内容自适应时,右栏一旦长高就把行撑开,左列跟着 height:100% 一起变高(实测症状)。 */
|
|
537
|
+
.cwd-card { display: flex; flex-direction: column; height: 100%; min-width: 0; min-height: 0; border: .5px solid var(--dsw-alias-border-l1); border-radius: 14px; background: var(--cwd-card); overflow: hidden; }
|
|
538
|
+
.cwd-toolbar { display: flex; flex: none; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); }
|
|
539
|
+
.cwd-field { display: flex; align-items: center; gap: 6px; flex: 1 1 170px; min-width: 0; height: 34px; padding: 0 10px; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-tertiary); }
|
|
540
|
+
.cwd-field input { flex: 1 1 auto; min-width: 0; height: 100%; padding: 0; border: none; outline: none; background: transparent; color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 13px; }
|
|
541
|
+
.cwd-field input::placeholder { color: var(--dsw-alias-label-tertiary); }
|
|
542
|
+
.cwd-pill { display: inline-flex; align-items: center; gap: 6px; flex: none; max-width: 160px; height: 34px; padding: 0 12px; border: none; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-secondary); font-family: inherit; font-size: 12.5px; line-height: 20px; cursor: pointer; }
|
|
543
|
+
.cwd-pill:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-accent); color: var(--dsw-alias-label-primary); }
|
|
544
|
+
.cwd-pill:disabled { opacity: .45; cursor: not-allowed; }
|
|
545
|
+
.cwd-pill span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
546
|
+
.cwd-groupcreate { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
|
|
547
|
+
.cwd-groupcreate input { width: 104px; height: 34px; padding: 0 10px; border: .5px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-module-platform); color: var(--dsw-alias-label-primary); font-family: inherit; font-size: 12.5px; }
|
|
548
|
+
.cwd-thead, .cwd-row { display: grid; grid-template-columns: minmax(0, 1.6fr) 92px 84px 40px; gap: 10px; align-items: center; }
|
|
549
|
+
.cwd-thead { flex: none; padding: 8px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); font-size: 11px; line-height: 16px; letter-spacing: .2px; color: var(--dsw-alias-label-tertiary); white-space: nowrap; }
|
|
550
|
+
.cwd-right { text-align: right; }
|
|
551
|
+
.cwd-tablebody { flex: 1; min-height: 0; overflow-y: auto; border-bottom: .5px solid var(--dsw-alias-border-l2); }
|
|
552
|
+
.cwd-row { padding: 9px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); transition: background .15s var(--ds-ease-in-out); }
|
|
553
|
+
.cwd-row:last-of-type { border-bottom: none; }
|
|
554
|
+
.cwd-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
555
|
+
.cwd-row[aria-current="true"] { background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 10%, transparent); }
|
|
556
|
+
.cwd-nameline { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
557
|
+
.cwd-cellname { display: flex; flex-direction: column; gap: 1px; min-width: 0; padding: 0; border: none; background: transparent; color: inherit; font-family: inherit; text-align: left; cursor: pointer; }
|
|
558
|
+
.cwd-nametext { flex: 0 1 auto; min-width: 0; font-size: 14px; line-height: 19px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
559
|
+
.cwd-codeline { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 11px; line-height: 15px; color: var(--dsw-alias-label-tertiary); }
|
|
560
|
+
.cwd-code { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
561
|
+
.cwd-price { text-align: right; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
562
|
+
.cwd-pct { text-align: right; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
563
|
+
.cwd-up { color: var(--capital-watchlist-up); }
|
|
564
|
+
.cwd-down { color: var(--capital-watchlist-down); }
|
|
565
|
+
.cwd-flat { color: var(--dsw-alias-label-secondary); }
|
|
566
|
+
.cwd-stale { color: var(--dsw-alias-label-secondary); }
|
|
567
|
+
.cwd-rowactions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 2px; }
|
|
568
|
+
.cwd-iconbtn { flex: none; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: var(--dsw-radius-sm); background: transparent; color: var(--dsw-alias-label-secondary); cursor: pointer; }
|
|
569
|
+
.cwd-iconbtn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover-accent); color: var(--dsw-alias-label-primary); }
|
|
570
|
+
.cwd-iconbtn:disabled { opacity: .45; cursor: not-allowed; }
|
|
571
|
+
.cwd-detail { display: flex; flex: 1; flex-direction: column; gap: 12px; min-height: 0; padding: 16px; overflow-y: auto; }
|
|
572
|
+
.cwd-detailhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; min-width: 0; }
|
|
573
|
+
.cwd-detailname { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 16px; line-height: 22px; font-weight: 600; }
|
|
574
|
+
.cwd-detailtext { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
575
|
+
.cwd-detailcode { margin-top: 3px; font-size: 12px; line-height: 17px; color: var(--dsw-alias-label-tertiary); }
|
|
576
|
+
.cwd-bigquote { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; }
|
|
577
|
+
.cwd-bigprice { font-size: 34px; line-height: 40px; font-weight: 650; font-variant-numeric: tabular-nums; }
|
|
578
|
+
.cwd-bigpct { font-size: 14px; line-height: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
579
|
+
.cwd-quoterow { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; }
|
|
580
|
+
.cwd-meta { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 20px; padding-bottom: 4px; }
|
|
581
|
+
.cwd-metaitem { display: flex; align-items: baseline; gap: 6px; }
|
|
582
|
+
.cwd-metalabel { flex: none; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
|
|
583
|
+
.cwd-metavalue { font-size: 12px; line-height: 16px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
584
|
+
.cwd-block { flex: none; padding-top: 12px; border-top: .5px solid var(--dsw-alias-border-l2); }
|
|
585
|
+
.cwd-block-chart { flex: 1 1 0; display: flex; flex-direction: column; min-height: 200px; }
|
|
586
|
+
/* Folded block keeps only its title row, so it stops competing for height. */
|
|
587
|
+
.cwd-block-chart.cwd-folded { flex: none; min-height: 0; }
|
|
588
|
+
.cwd-blockhead { display: flex; flex: none; align-items: baseline; gap: 12px; margin-bottom: 8px; }
|
|
589
|
+
.cwd-blocktitle { flex: none; font-size: 12.5px; line-height: 18px; font-weight: 600; }
|
|
590
|
+
.cwd-blocknote { margin-left: auto; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
|
|
591
|
+
.cwd-blockfold { flex: none; padding: 0 2px; border: 0; background: none; font-family: inherit; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); cursor: pointer; }
|
|
592
|
+
.cwd-blockfold:hover { color: var(--dsw-alias-label-primary); }
|
|
593
|
+
.cwd-chart { flex: 1; min-height: 150px; display: grid; place-items: center; padding: 12px; border: 1px dashed var(--dsw-alias-border-l2); border-radius: 10px; background: repeating-linear-gradient(180deg, color-mix(in srgb, var(--dsw-alias-border-l2) 60%, transparent) 0 1px, transparent 1px 36px), var(--dsw-alias-bg-module-platform); text-align: center; }
|
|
594
|
+
.cwd-charttext { font-size: 12.5px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-label-secondary); }
|
|
595
|
+
.cwd-charthint { margin-top: 4px; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
|
|
596
|
+
.cwd-trendstats { display: flex; flex: 1 1 auto; flex-wrap: wrap; gap: 2px 14px; min-width: 0; }
|
|
597
|
+
.cwd-trendstat { display: flex; align-items: baseline; gap: 5px; font-size: 11px; line-height: 17px; }
|
|
598
|
+
.cwd-trendstat span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
|
599
|
+
.cwd-trendstat span:first-child { flex: none; color: var(--dsw-alias-label-tertiary); }
|
|
600
|
+
.cwd-trendstat span:last-child { font-variant-numeric: tabular-nums; }
|
|
601
|
+
.cwd-chartbox { position: relative; flex: 1; min-height: 120px; min-width: 0; overflow: hidden; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); }
|
|
602
|
+
/* The daily pane shares the SVG contract above (absolute child, determinate height): a flexed chart
|
|
603
|
+
next to a scrolled column is exactly how the container used to grow. */
|
|
604
|
+
.cwd-block-kline { flex: 1 1 0; display: flex; flex-direction: column; min-height: 220px; }
|
|
605
|
+
.cwd-klinebox { position: relative; flex: 1; min-height: 140px; min-width: 0; overflow: hidden; border-radius: 10px; background: var(--dsw-alias-bg-module-platform); }
|
|
606
|
+
.cwd-malegend { display: flex; flex: 1 1 auto; flex-wrap: wrap; gap: 2px 12px; min-width: 0; font-size: 11px; line-height: 16px; font-variant-numeric: tabular-nums; }
|
|
607
|
+
.cwd-candle-up { fill: var(--capital-watchlist-up); stroke: var(--capital-watchlist-up); stroke-width: 1; }
|
|
608
|
+
.cwd-candle-down { fill: var(--capital-watchlist-down); stroke: var(--capital-watchlist-down); stroke-width: 1; }
|
|
609
|
+
.cwd-maline { fill: none; stroke-width: 1.1; stroke-linejoin: round; }
|
|
610
|
+
.cwd-ma5 { color: var(--dsw-alias-label-primary); stroke: var(--dsw-alias-label-primary); }
|
|
611
|
+
.cwd-ma10 { color: var(--dsw-alias-state-warn-primary); stroke: var(--dsw-alias-state-warn-primary); }
|
|
612
|
+
.cwd-ma20 { color: var(--dsw-alias-brand-primary); stroke: var(--dsw-alias-brand-primary); }
|
|
613
|
+
.cwd-ma60 { color: var(--dsw-alias-label-tertiary); stroke: var(--dsw-alias-label-tertiary); }
|
|
614
|
+
/* ⛔ 绝对定位不是为了叠层:SVG 一旦参与流式布局,viewBox 的宽高比会反推父盒高度,
|
|
615
|
+
量测回写就把容器越撑越大(实测逐帧增长)。它必须永远影响不了自己的容器。 */
|
|
616
|
+
.cwd-chartsvg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: pan-y; }
|
|
617
|
+
.cwd-chartaxis { fill: var(--dsw-alias-label-tertiary); font-size: 10.5px; font-variant-numeric: tabular-nums; }
|
|
618
|
+
.cwd-chartbaselabel { fill: var(--dsw-alias-label-secondary); }
|
|
619
|
+
.cwd-chartgrid { stroke: color-mix(in srgb, var(--dsw-alias-border-l2) 55%, transparent); stroke-width: 1; shape-rendering: crispEdges; }
|
|
620
|
+
.cwd-chartsep { stroke: var(--dsw-alias-border-l2); stroke-width: 1; stroke-dasharray: 2 3; }
|
|
621
|
+
.cwd-chartline { fill: none; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
|
|
622
|
+
.cwd-chartavg { fill: none; stroke: var(--dsw-alias-state-business-primary); stroke-width: 1; stroke-dasharray: 3 3; opacity: .85; }
|
|
623
|
+
.cwd-chartbase { stroke: var(--dsw-alias-label-tertiary); stroke-width: 1; opacity: .7; }
|
|
624
|
+
.cwd-chartcross { stroke: var(--dsw-alias-label-tertiary); stroke-width: 1; stroke-dasharray: 3 3; opacity: .8; }
|
|
625
|
+
.cwd-chartdot { fill: currentColor; }
|
|
626
|
+
.cwd-vol-up { fill: var(--capital-watchlist-up); opacity: .55; }
|
|
627
|
+
.cwd-vol-down { fill: var(--capital-watchlist-down); opacity: .55; }
|
|
628
|
+
.cwd-charttip { position: absolute; top: 8px; min-width: 150px; padding: 7px 9px; border-radius: 8px; border: .5px solid var(--dsw-alias-border-l2); background: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1)); pointer-events: none; }
|
|
629
|
+
.cwd-charttiptime { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
|
|
630
|
+
.cwd-charttipprice { font-size: 13px; line-height: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
|
|
631
|
+
.cwd-charttiprow { display: flex; justify-content: space-between; gap: 10px; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
|
|
632
|
+
.cwd-empty { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 34px 18px; text-align: center; }
|
|
633
|
+
.cwd-emptytitle { font-size: 14px; line-height: 20px; font-weight: 600; }
|
|
634
|
+
.cwd-emptyhint { margin: 6px 0 0; font-size: 12.5px; line-height: 19px; color: var(--dsw-alias-label-tertiary); }
|
|
635
|
+
.cwd-notice { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
|
|
636
|
+
.cwd-notice-danger { color: var(--dsw-alias-state-error-primary); }
|
|
637
|
+
.cwd-error { flex: none; padding: 8px 14px; border-bottom: .5px solid var(--dsw-alias-border-l2); font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-error-primary); }
|
|
638
|
+
.cwd-menuhint { padding: 6px 10px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }
|
|
639
|
+
.cwd-menulist { width: 208px; }
|
|
640
|
+
.cwd-menulist button { box-sizing: border-box; }
|
|
641
|
+
.cwd-field:focus-within { outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); outline-offset: 1px; }
|
|
642
|
+
.cwd-page button:focus-visible, .cwd-groupcreate input:focus-visible { outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); outline-offset: 1px; }
|
|
643
|
+
.cwd-skeleton { display: block; height: 12px; border-radius: 6px; background: var(--dsw-alias-bg-skeleton); }
|
|
644
|
+
@media (max-width: 1040px) { .cwd-body { flex: none; grid-template-columns: minmax(0, 1fr); gap: 16px; height: auto; max-height: none; } .cwd-card { height: auto; } .cwd-tablebody { flex: none; max-height: 60vh; } .cwd-chart { flex: none; height: 200px; } .cwd-chartbox { flex: none; height: 260px; } .cwd-klinebox { flex: none; height: 260px; } .cwd-block-chart, .cwd-block-kline { flex: none; } }
|
|
645
|
+
@media (max-width: 720px) { .cwd-inner { padding: 20px 16px 32px; } .cwd-thead, .cwd-row { grid-template-columns: minmax(0, 1.5fr) 78px 72px 36px; gap: 8px; } .cwd-thead { padding: 8px 10px; } .cwd-row { padding: 9px 10px; } }
|
|
389
646
|
`
|
|
390
647
|
|
|
391
648
|
function installStyles() {
|
|
@@ -1231,6 +1488,960 @@ function WatchlistDialog({ useDialog, surface, t, inputActions }) {
|
|
|
1231
1488
|
)
|
|
1232
1489
|
}
|
|
1233
1490
|
|
|
1491
|
+
/* ---------------------------------------------------------------------------
|
|
1492
|
+
* 行情工作台:左侧栏「自选股」入口 + main 面板。
|
|
1493
|
+
* 报价仍只走 /capital-watchlist(同一 host 路由、同一套失败码);分组只落本机。
|
|
1494
|
+
* 分时与成交量目前没有数据源,画占位并写明原因,不补造走势。
|
|
1495
|
+
* ------------------------------------------------------------------------ */
|
|
1496
|
+
const DESK_PANEL_ID = `${ENTRY_NAME}:desk`
|
|
1497
|
+
const DESK_GROUPS_KEY = 'capital.watchlist.desk.groups.v1'
|
|
1498
|
+
const DESK_ALL = '__all__'
|
|
1499
|
+
/** Monotonic request id for the desk's series: a late answer must not overwrite a newer selection. */
|
|
1500
|
+
let deskTrendSequence = 0
|
|
1501
|
+
let deskKlineSequence = 0
|
|
1502
|
+
|
|
1503
|
+
function readDeskGroups() {
|
|
1504
|
+
const empty = { names: [], assignments: {} }
|
|
1505
|
+
try {
|
|
1506
|
+
const parsed = JSON.parse(localStorage.getItem(DESK_GROUPS_KEY) ?? '{}')
|
|
1507
|
+
if (parsed === null || typeof parsed !== 'object') return empty
|
|
1508
|
+
if (!Array.isArray(parsed.names)) return empty
|
|
1509
|
+
if (parsed.assignments === null || typeof parsed.assignments !== 'object') return empty
|
|
1510
|
+
return {
|
|
1511
|
+
names: parsed.names.filter((name) => typeof name === 'string' && name.length > 0).slice(0, 20),
|
|
1512
|
+
assignments: parsed.assignments,
|
|
1513
|
+
}
|
|
1514
|
+
} catch {
|
|
1515
|
+
return empty
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
function writeDeskGroups(value) {
|
|
1520
|
+
try {
|
|
1521
|
+
localStorage.setItem(DESK_GROUPS_KEY, JSON.stringify(value))
|
|
1522
|
+
} catch {
|
|
1523
|
+
// Private mode: groups stay in memory for this page.
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
const deskGroupsOf = (groups, thscode) => {
|
|
1528
|
+
const names = groups.assignments[thscode]
|
|
1529
|
+
return Array.isArray(names) ? names : []
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
/** Missing change is missing (holiday / halted), never 0.00%. */
|
|
1533
|
+
const deskPctOf = (quote) => (quote !== null && quote !== undefined && typeof quote.change_pct === 'number' && Number.isFinite(quote.change_pct) ? quote.change_pct : null)
|
|
1534
|
+
const deskToneOf = (value) => (value === null ? 'cwd-flat' : value > 0 ? 'cwd-up' : value < 0 ? 'cwd-down' : 'cwd-flat')
|
|
1535
|
+
const deskPctText = (value) => (value === null ? '—' : `${value > 0 ? '+' : ''}${value.toFixed(2)}%`)
|
|
1536
|
+
/** Comma grouping is the market convention here, so it does not follow the UI locale. */
|
|
1537
|
+
const deskPriceFormat = new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
|
1538
|
+
const deskPriceText = (quote) => (quote !== null && quote !== undefined && typeof quote.price === 'number' && Number.isFinite(quote.price) ? deskPriceFormat.format(quote.price) : '—')
|
|
1539
|
+
/** Any number → grouped text; every price on the desk keeps two decimals, indices included. */
|
|
1540
|
+
const deskNumberText = (value) => (typeof value === 'number' && Number.isFinite(value) ? deskPriceFormat.format(value) : '—')
|
|
1541
|
+
|
|
1542
|
+
/** 万 / 亿 scaling for totals; the suffix stays Chinese in both locales, like the market comma. */
|
|
1543
|
+
function deskScaledText(value, digits = 2) {
|
|
1544
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) return '—'
|
|
1545
|
+
const size = Math.abs(value)
|
|
1546
|
+
if (size >= 1e8) return `${(value / 1e8).toFixed(digits)}亿`
|
|
1547
|
+
if (size >= 1e4) return `${(value / 1e4).toFixed(digits)}万`
|
|
1548
|
+
return new Intl.NumberFormat('en-US', { maximumFractionDigits: digits }).format(value)
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
const deskMinutesOf = (time) => (typeof time === 'string' && time.length >= 5 ? Number(time.slice(0, 2)) * 60 + Number(time.slice(3, 5)) : 0)
|
|
1552
|
+
|
|
1553
|
+
function deskVolumeText(value, unit, t) {
|
|
1554
|
+
const text = deskScaledText(value)
|
|
1555
|
+
if (text === '—') return text
|
|
1556
|
+
if (unit === 'lot') return `${text}${t('desk.lot')}`
|
|
1557
|
+
if (unit === 'share') return `${text}${t('desk.share')}`
|
|
1558
|
+
return text
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
function deskAmountText(value, currency) {
|
|
1562
|
+
const text = deskScaledText(value)
|
|
1563
|
+
if (text === '—') return text
|
|
1564
|
+
return currency === null || currency === undefined || currency === 'CNY' ? text : `${text} ${currency}`
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
/**
|
|
1568
|
+
* The x axis is the trading clock, not the point count: a 09:32 print must stay near the left edge
|
|
1569
|
+
* instead of stretching over the whole pane (that is what turns four points into four fat bars).
|
|
1570
|
+
* The lunch break takes no width, so a slot is one trading minute and `total` is the day's length.
|
|
1571
|
+
*/
|
|
1572
|
+
const TREND_SESSIONS = {
|
|
1573
|
+
'a-share': [[570, 690], [780, 900]],
|
|
1574
|
+
hk: [[570, 720], [780, 960]],
|
|
1575
|
+
us: [[570, 960]],
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
const deskClockText = (minutes) => `${String(Math.floor(minutes / 60)).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`
|
|
1579
|
+
|
|
1580
|
+
function deskSessionOf(market) {
|
|
1581
|
+
const spans = []
|
|
1582
|
+
let total = 0
|
|
1583
|
+
for (const [open, close] of TREND_SESSIONS[market] ?? TREND_SESSIONS.us) {
|
|
1584
|
+
spans.push([open, close, total])
|
|
1585
|
+
total += close - open
|
|
1586
|
+
}
|
|
1587
|
+
return { spans, total }
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
/** Minute of day → compressed slot; a print outside the session (the HK closing auction) lands on the edge. */
|
|
1591
|
+
function deskSlotOf(session, minutes) {
|
|
1592
|
+
for (const [open, close, base] of session.spans) {
|
|
1593
|
+
if (minutes <= open) return base
|
|
1594
|
+
if (minutes < close) return base + minutes - open
|
|
1595
|
+
}
|
|
1596
|
+
return session.total
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
/** Half-hour grid; a tick landing on the previous tick's slot (11:30 and 13:00 share one) is dropped. */
|
|
1600
|
+
function deskTicksOf(session) {
|
|
1601
|
+
const ticks = []
|
|
1602
|
+
for (const [open, close, base] of session.spans) {
|
|
1603
|
+
for (let minutes = open; minutes <= close; minutes += 30) {
|
|
1604
|
+
const slot = base + minutes - open
|
|
1605
|
+
if (ticks.length === 0 || ticks[ticks.length - 1].slot !== slot) ticks.push({ time: deskClockText(minutes), slot })
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
return ticks
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
/**
|
|
1612
|
+
* Same-session trend drawn in plain SVG: price line + area, previous-close baseline, VWAP line,
|
|
1613
|
+
* volume histogram and a pointer crosshair. Geometry is computed in pixels (the box is measured),
|
|
1614
|
+
* so labels and dashes stay crisp at any width; nothing here fetches or invents a point.
|
|
1615
|
+
*/
|
|
1616
|
+
function IntradayChart({ data, t }) {
|
|
1617
|
+
const [box, setBox] = useState({ width: 720, height: 300 })
|
|
1618
|
+
const [cursor, setCursor] = useState(null)
|
|
1619
|
+
const host = useRef(null)
|
|
1620
|
+
|
|
1621
|
+
useEffect(() => {
|
|
1622
|
+
const element = host.current
|
|
1623
|
+
if (element === null || element === undefined) return undefined
|
|
1624
|
+
// Integer `clientWidth` rounding plus a content-sized box is exactly how a chart grows by a
|
|
1625
|
+
// pixel per frame; measure the fractional rect and ignore sub-2px jitter. Returning the same
|
|
1626
|
+
// object makes React bail out, so a wobbling layout can never re-enter this loop.
|
|
1627
|
+
const measure = () => {
|
|
1628
|
+
const rect = element.getBoundingClientRect()
|
|
1629
|
+
if (!(rect.width > 0) || !(rect.height > 0)) return
|
|
1630
|
+
const width = Math.max(280, Math.round(rect.width))
|
|
1631
|
+
const height = Math.max(180, Math.round(rect.height))
|
|
1632
|
+
setBox((current) => (Math.abs(current.width - width) < 2 && Math.abs(current.height - height) < 2 ? current : { width, height }))
|
|
1633
|
+
}
|
|
1634
|
+
measure()
|
|
1635
|
+
if (typeof ResizeObserver === 'undefined') return undefined
|
|
1636
|
+
const observer = new ResizeObserver(measure)
|
|
1637
|
+
observer.observe(element)
|
|
1638
|
+
return () => observer.disconnect()
|
|
1639
|
+
}, [])
|
|
1640
|
+
|
|
1641
|
+
const points = data.points
|
|
1642
|
+
const prevClose = data.prev_close
|
|
1643
|
+
const width = box.width
|
|
1644
|
+
const height = box.height
|
|
1645
|
+
// Gutters fit `24,547.66` on the left and `+10.00%` on the right at 10.5px without clipping.
|
|
1646
|
+
const left = 66
|
|
1647
|
+
const right = 54
|
|
1648
|
+
const top = 12
|
|
1649
|
+
const axisHeight = 18
|
|
1650
|
+
const volumeHeight = Math.round(Math.min(70, Math.max(30, height * 0.22)))
|
|
1651
|
+
// Reserve the bottom axis band: the volume pane must stop above the tick labels, not under them.
|
|
1652
|
+
const priceHeight = Math.max(60, height - top - axisHeight - volumeHeight - 10)
|
|
1653
|
+
const plotWidth = Math.max(60, width - left - right)
|
|
1654
|
+
const session = deskSessionOf(data.market)
|
|
1655
|
+
const slotWidth = plotWidth / session.total
|
|
1656
|
+
|
|
1657
|
+
const values = points.map((point) => point[1])
|
|
1658
|
+
const floorValue = Math.min(prevClose, ...values)
|
|
1659
|
+
const peakValue = Math.max(prevClose, ...values)
|
|
1660
|
+
const margin = (peakValue - floorValue) * 0.06 || Math.max(peakValue * 0.002, 0.01)
|
|
1661
|
+
const low = floorValue - margin
|
|
1662
|
+
const high = peakValue + margin
|
|
1663
|
+
const scaleY = (value) => top + ((high - value) / (high - low)) * priceHeight
|
|
1664
|
+
const slots = points.map((point) => deskSlotOf(session, deskMinutesOf(point[0])))
|
|
1665
|
+
const scaleX = (slot) => left + slot * slotWidth
|
|
1666
|
+
const firstX = scaleX(slots[0]).toFixed(1)
|
|
1667
|
+
const lastX = scaleX(slots[points.length - 1]).toFixed(1)
|
|
1668
|
+
|
|
1669
|
+
const tone = data.last === null || data.last >= prevClose ? 'up' : 'down'
|
|
1670
|
+
const stroke = tone === 'up' ? 'var(--capital-watchlist-up)' : 'var(--capital-watchlist-down)'
|
|
1671
|
+
const pricePath = points.map((point, index) => `${index === 0 ? 'M' : 'L'}${scaleX(slots[index]).toFixed(1)} ${scaleY(point[1]).toFixed(1)}`).join('')
|
|
1672
|
+
const bottom = (top + priceHeight).toFixed(1)
|
|
1673
|
+
const areaPath = `${pricePath}L${lastX} ${bottom}L${firstX} ${bottom}Z`
|
|
1674
|
+
const averagePath = points.reduce((path, point, index) => (point[2] === null ? path : `${path}${path === '' ? 'M' : 'L'}${scaleX(slots[index]).toFixed(1)} ${scaleY(point[2]).toFixed(1)}`), '')
|
|
1675
|
+
|
|
1676
|
+
const volumeTop = top + priceHeight + 10
|
|
1677
|
+
const maxVolume = Math.max(1, ...points.map((point) => point[3] ?? 0))
|
|
1678
|
+
// One bar per trading minute: thin by construction, never sized by how many points happened to arrive.
|
|
1679
|
+
const barWidth = Math.max(1, Math.min(10, slotWidth * 0.72))
|
|
1680
|
+
const baseY = scaleY(prevClose)
|
|
1681
|
+
const gridLines = [0, 1, 2, 3, 4].map((step) => {
|
|
1682
|
+
const value = low + ((high - low) * step) / 4
|
|
1683
|
+
return { value, y: scaleY(value), pct: ((value - prevClose) / prevClose) * 100 }
|
|
1684
|
+
}).filter((line) => Math.abs(line.y - baseY) > 9)
|
|
1685
|
+
|
|
1686
|
+
const sessionBreak = session.spans.length > 1 ? session.spans[1][2] : null
|
|
1687
|
+
const allTicks = deskTicksOf(session)
|
|
1688
|
+
const tickStep = width >= 620 ? 1 : 2
|
|
1689
|
+
const ticks = allTicks.filter((tick, order) => order % tickStep === 0 || order === allTicks.length - 1)
|
|
1690
|
+
|
|
1691
|
+
const focus = cursor === null || cursor < 0 || cursor >= points.length ? null : points[cursor]
|
|
1692
|
+
const focusX = focus === null ? 0 : scaleX(slots[cursor])
|
|
1693
|
+
const focusY = focus === null ? 0 : scaleY(focus[1])
|
|
1694
|
+
const tipLeft = Math.min(width - 172, Math.max(8, focusX + 12))
|
|
1695
|
+
const summary = `${data.thscode} ${data.session_date ?? ''} ${t('desk.intraday')} · ${t('desk.trendOpen')} ${deskNumberText(data.open)} · ${t('desk.trendHigh')} ${deskNumberText(data.high)} · ${t('desk.trendLow')} ${deskNumberText(data.low)} · ${t('desk.trendAvg')} ${deskNumberText(data.avg)}`
|
|
1696
|
+
|
|
1697
|
+
const onMove = (event) => {
|
|
1698
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
1699
|
+
if (!(rect.width > 0)) return
|
|
1700
|
+
const slot = Math.max(0, Math.min(session.total, ((event.clientX - rect.left - left) / plotWidth) * session.total))
|
|
1701
|
+
let nearest = 0
|
|
1702
|
+
for (let index = 1; index < slots.length; index += 1) {
|
|
1703
|
+
if (Math.abs(slots[index] - slot) < Math.abs(slots[nearest] - slot)) nearest = index
|
|
1704
|
+
}
|
|
1705
|
+
setCursor(nearest)
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
return h('div', { className: 'cwd-chartbox', ref: host },
|
|
1709
|
+
h('svg', {
|
|
1710
|
+
className: 'cwd-chartsvg',
|
|
1711
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
1712
|
+
role: 'img',
|
|
1713
|
+
'aria-label': summary,
|
|
1714
|
+
onPointerMove: onMove,
|
|
1715
|
+
onPointerLeave: () => setCursor(null),
|
|
1716
|
+
},
|
|
1717
|
+
h('defs', null,
|
|
1718
|
+
h('linearGradient', { id: 'cwd-trend-fill', x1: '0', y1: '0', x2: '0', y2: '1' },
|
|
1719
|
+
h('stop', { offset: '0%', style: { stopColor: stroke, stopOpacity: 0.2 } }),
|
|
1720
|
+
h('stop', { offset: '100%', style: { stopColor: stroke, stopOpacity: 0 } }))),
|
|
1721
|
+
gridLines.map((line) => h('g', { key: `grid-${line.value.toFixed(4)}` },
|
|
1722
|
+
h('line', { className: 'cwd-chartgrid', x1: left, x2: left + plotWidth, y1: line.y, y2: line.y }),
|
|
1723
|
+
h('text', { className: 'cwd-chartaxis', x: left - 8, y: line.y + 3.5, textAnchor: 'end' }, deskNumberText(line.value)),
|
|
1724
|
+
h('text', { className: 'cwd-chartaxis', x: left + plotWidth + 8, y: line.y + 3.5 }, `${line.pct > 0 ? '+' : ''}${line.pct.toFixed(2)}%`))),
|
|
1725
|
+
ticks.map((tick) => h('line', {
|
|
1726
|
+
key: `grid-${tick.time}`,
|
|
1727
|
+
className: 'cwd-chartgrid',
|
|
1728
|
+
x1: scaleX(tick.slot),
|
|
1729
|
+
x2: scaleX(tick.slot),
|
|
1730
|
+
y1: top,
|
|
1731
|
+
y2: volumeTop + volumeHeight,
|
|
1732
|
+
})),
|
|
1733
|
+
sessionBreak === null ? null : h('line', {
|
|
1734
|
+
className: 'cwd-chartsep',
|
|
1735
|
+
x1: scaleX(sessionBreak),
|
|
1736
|
+
x2: scaleX(sessionBreak),
|
|
1737
|
+
y1: top,
|
|
1738
|
+
y2: volumeTop + volumeHeight,
|
|
1739
|
+
}),
|
|
1740
|
+
h('path', { className: 'cwd-chartarea', d: areaPath, fill: 'url(#cwd-trend-fill)' }),
|
|
1741
|
+
points.map((point, index) => {
|
|
1742
|
+
const value = point[3] ?? 0
|
|
1743
|
+
const barHeight = Math.max(0, (value / maxVolume) * volumeHeight)
|
|
1744
|
+
const previous = index === 0 ? prevClose : points[index - 1][1]
|
|
1745
|
+
const center = scaleX(slots[index] + 0.5)
|
|
1746
|
+
return h('rect', {
|
|
1747
|
+
key: `vol-${index}`,
|
|
1748
|
+
className: point[1] >= previous ? 'cwd-vol-up' : 'cwd-vol-down',
|
|
1749
|
+
x: (Math.min(left + plotWidth - barWidth, Math.max(left, center - barWidth / 2))).toFixed(1),
|
|
1750
|
+
y: (volumeTop + volumeHeight - barHeight).toFixed(1),
|
|
1751
|
+
width: barWidth.toFixed(1),
|
|
1752
|
+
height: Math.max(0.5, barHeight).toFixed(1),
|
|
1753
|
+
})
|
|
1754
|
+
}),
|
|
1755
|
+
h('path', { className: 'cwd-chartline', d: pricePath, style: { stroke } }),
|
|
1756
|
+
averagePath === '' ? null : h('path', { className: 'cwd-chartavg', d: averagePath }),
|
|
1757
|
+
h('line', { className: 'cwd-chartbase', x1: left, x2: left + plotWidth, y1: baseY, y2: baseY, strokeDasharray: '4 3' }),
|
|
1758
|
+
h('text', { className: 'cwd-chartaxis cwd-chartbaselabel', x: left - 8, y: baseY + 3.5, textAnchor: 'end' }, deskNumberText(prevClose)),
|
|
1759
|
+
ticks.map((tick) => h('text', {
|
|
1760
|
+
key: `tick-${tick.time}`,
|
|
1761
|
+
className: 'cwd-chartaxis',
|
|
1762
|
+
x: scaleX(tick.slot),
|
|
1763
|
+
y: height - 5,
|
|
1764
|
+
textAnchor: tick.slot === 0 ? 'start' : tick.slot >= session.total ? 'end' : 'middle',
|
|
1765
|
+
}, tick.time)),
|
|
1766
|
+
focus === null ? null : h('g', null,
|
|
1767
|
+
h('line', { className: 'cwd-chartcross', x1: focusX, x2: focusX, y1: top, y2: volumeTop + volumeHeight }),
|
|
1768
|
+
h('line', { className: 'cwd-chartcross', x1: left, x2: left + plotWidth, y1: focusY, y2: focusY }),
|
|
1769
|
+
h('circle', { className: `cwd-chartdot ${tone === 'up' ? 'cwd-up' : 'cwd-down'}`, cx: focusX, cy: focusY, r: 3 })),
|
|
1770
|
+
),
|
|
1771
|
+
focus === null ? null : h('div', { className: 'cwd-charttip', style: { left: `${tipLeft}px` } },
|
|
1772
|
+
h('div', { className: 'cwd-charttiptime' }, focus[0]),
|
|
1773
|
+
h('div', { className: `cwd-charttipprice ${tone === 'up' ? 'cwd-up' : 'cwd-down'}` },
|
|
1774
|
+
`${deskNumberText(focus[1])} ${deskPctText(((focus[1] - prevClose) / prevClose) * 100)}`),
|
|
1775
|
+
focus[2] === null ? null : h('div', { className: 'cwd-charttiprow' }, h('span', null, t('desk.trendAvg')), h('span', null, deskNumberText(focus[2]))),
|
|
1776
|
+
focus[3] === null ? null : h('div', { className: 'cwd-charttiprow' }, h('span', null, t('desk.trendVolume')), h('span', null, deskVolumeText(focus[3], data.volume_unit, t)))))
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
/** Moving averages over a close series; the leading `window-1` slots stay null so a line never starts at the first bar. */
|
|
1780
|
+
function movingAverage(bars, window) {
|
|
1781
|
+
const values = new Array(bars.length).fill(null)
|
|
1782
|
+
let sum = 0
|
|
1783
|
+
for (let index = 0; index < bars.length; index += 1) {
|
|
1784
|
+
sum += bars[index].close
|
|
1785
|
+
if (index >= window) sum -= bars[index - window].close
|
|
1786
|
+
if (index >= window - 1) values[index] = sum / window
|
|
1787
|
+
}
|
|
1788
|
+
return values
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
/** Four lines is what a 700px pane can keep apart; MA30 would sit on top of MA20 most of the time. */
|
|
1792
|
+
const MA_WINDOWS = [5, 10, 20, 60]
|
|
1793
|
+
|
|
1794
|
+
/**
|
|
1795
|
+
* Daily candles for the desk. Same pixel geometry and the same measured box as the intraday pane
|
|
1796
|
+
* (absolute SVG, 2px deadband, no intrinsic sizing), so the two charts stay aligned and neither can
|
|
1797
|
+
* push its container. Candles are red on up and green on down, the A-share convention used above.
|
|
1798
|
+
*/
|
|
1799
|
+
function DailyChart({ data, t }) {
|
|
1800
|
+
const [box, setBox] = useState({ width: 720, height: 300 })
|
|
1801
|
+
const [cursor, setCursor] = useState(null)
|
|
1802
|
+
const host = useRef(null)
|
|
1803
|
+
|
|
1804
|
+
useEffect(() => {
|
|
1805
|
+
const element = host.current
|
|
1806
|
+
if (element === null || element === undefined) return undefined
|
|
1807
|
+
const measure = () => {
|
|
1808
|
+
const rect = element.getBoundingClientRect()
|
|
1809
|
+
if (!(rect.width > 0) || !(rect.height > 0)) return
|
|
1810
|
+
const width = Math.max(280, Math.round(rect.width))
|
|
1811
|
+
const height = Math.max(180, Math.round(rect.height))
|
|
1812
|
+
setBox((current) => (Math.abs(current.width - width) < 2 && Math.abs(current.height - height) < 2 ? current : { width, height }))
|
|
1813
|
+
}
|
|
1814
|
+
measure()
|
|
1815
|
+
if (typeof ResizeObserver === 'undefined') return undefined
|
|
1816
|
+
const observer = new ResizeObserver(measure)
|
|
1817
|
+
observer.observe(element)
|
|
1818
|
+
return () => observer.disconnect()
|
|
1819
|
+
}, [])
|
|
1820
|
+
|
|
1821
|
+
const bars = data.bars
|
|
1822
|
+
const width = box.width
|
|
1823
|
+
const height = box.height
|
|
1824
|
+
const left = 66
|
|
1825
|
+
const right = 54
|
|
1826
|
+
const top = 10
|
|
1827
|
+
const axisHeight = 18
|
|
1828
|
+
const volumeHeight = Math.round(Math.min(64, Math.max(28, height * 0.2)))
|
|
1829
|
+
const priceHeight = Math.max(60, height - top - axisHeight - volumeHeight - 12)
|
|
1830
|
+
const plotWidth = Math.max(60, width - left - right)
|
|
1831
|
+
const slot = plotWidth / Math.max(1, bars.length)
|
|
1832
|
+
// Candles keep a gap so a dense series still reads as separate days instead of a solid block.
|
|
1833
|
+
const barWidth = Math.max(1, Math.min(14, slot * 0.62))
|
|
1834
|
+
|
|
1835
|
+
const highest = Math.max(...bars.map((bar) => bar.high))
|
|
1836
|
+
const lowest = Math.min(...bars.map((bar) => bar.low))
|
|
1837
|
+
const margin = (highest - lowest) * 0.06 || Math.max(highest * 0.01, 0.01)
|
|
1838
|
+
const high = highest + margin
|
|
1839
|
+
const low = lowest - margin
|
|
1840
|
+
const scaleY = (value) => top + ((high - value) / (high - low)) * priceHeight
|
|
1841
|
+
const scaleX = (index) => left + (index + 0.5) * slot
|
|
1842
|
+
|
|
1843
|
+
const volumeTop = top + priceHeight + 12
|
|
1844
|
+
const maxVolume = Math.max(1, ...bars.map((bar) => bar.volume))
|
|
1845
|
+
const scaleVolume = (value) => (value / maxVolume) * volumeHeight
|
|
1846
|
+
|
|
1847
|
+
const maSeries = MA_WINDOWS.map((window) => ({ window, values: movingAverage(bars, window) }))
|
|
1848
|
+
const lineOf = (values) => values.reduce((path, value, index) => (value === null ? path : `${path}${path === '' ? 'M' : 'L'}${scaleX(index).toFixed(1)} ${scaleY(value).toFixed(1)}`), '')
|
|
1849
|
+
|
|
1850
|
+
// Month boundaries only: twelve labels over 120 bars would collide, and every broker labels months.
|
|
1851
|
+
const monthTicks = []
|
|
1852
|
+
for (let index = 0; index < bars.length; index += 1) {
|
|
1853
|
+
const month = bars[index].date.slice(5, 7)
|
|
1854
|
+
if (index === 0 || month !== bars[index - 1].date.slice(5, 7)) monthTicks.push({ index, month })
|
|
1855
|
+
}
|
|
1856
|
+
// The year-prefixed first label is twice as wide as the others, so it only earns its place when the
|
|
1857
|
+
// next month boundary is far enough away — a partial first month (five bars of May) collides with it.
|
|
1858
|
+
const firstGapPx = monthTicks.length > 1 ? (monthTicks[1].index - monthTicks[0].index) * slot : Number.POSITIVE_INFINITY
|
|
1859
|
+
const ticks = monthTicks.map((tick, order) => ({
|
|
1860
|
+
index: tick.index,
|
|
1861
|
+
label: order === 0 && firstGapPx >= 56 ? `${bars[tick.index].date.slice(0, 4)}/${tick.month}` : tick.month,
|
|
1862
|
+
}))
|
|
1863
|
+
|
|
1864
|
+
const gridLines = [0, 1, 2, 3, 4].map((step) => {
|
|
1865
|
+
const value = high - ((high - low) * step) / 4
|
|
1866
|
+
return { value, y: scaleY(value) }
|
|
1867
|
+
})
|
|
1868
|
+
|
|
1869
|
+
const focus = cursor === null || cursor < 0 || cursor >= bars.length ? null : bars[cursor]
|
|
1870
|
+
const focusX = focus === null ? 0 : scaleX(cursor)
|
|
1871
|
+
const focusY = focus === null ? 0 : scaleY(focus.close)
|
|
1872
|
+
const focusPrev = cursor === null || cursor <= 0 ? null : bars[cursor - 1].close
|
|
1873
|
+
const focusPct = focus === null || focusPrev === null || focusPrev <= 0 ? null : ((focus.close - focusPrev) / focusPrev) * 100
|
|
1874
|
+
const tipLeft = Math.min(width - 186, Math.max(8, focusX + 12))
|
|
1875
|
+
const summary = `${data.thscode} ${t('desk.daily')} · ${bars.length} · ${deskNumberText(bars[bars.length - 1].close)}`
|
|
1876
|
+
|
|
1877
|
+
const onMove = (event) => {
|
|
1878
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
1879
|
+
if (!(rect.width > 0)) return
|
|
1880
|
+
const index = Math.round((event.clientX - rect.left - left) / slot - 0.5)
|
|
1881
|
+
setCursor(Math.max(0, Math.min(bars.length - 1, index)))
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
return h('div', { className: 'cwd-klinebox', ref: host },
|
|
1885
|
+
h('svg', {
|
|
1886
|
+
className: 'cwd-chartsvg',
|
|
1887
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
1888
|
+
role: 'img',
|
|
1889
|
+
'aria-label': summary,
|
|
1890
|
+
onPointerMove: onMove,
|
|
1891
|
+
onPointerLeave: () => setCursor(null),
|
|
1892
|
+
},
|
|
1893
|
+
gridLines.map((line) => h('g', { key: `grid-${line.value.toFixed(4)}` },
|
|
1894
|
+
h('line', { className: 'cwd-chartgrid', x1: left, x2: left + plotWidth, y1: line.y, y2: line.y }),
|
|
1895
|
+
h('text', { className: 'cwd-chartaxis', x: left - 8, y: line.y + 3.5, textAnchor: 'end' }, deskNumberText(line.value)))),
|
|
1896
|
+
ticks.map((tick) => h('g', { key: `tick-${tick.index}` },
|
|
1897
|
+
h('line', { className: 'cwd-chartgrid', x1: scaleX(tick.index), x2: scaleX(tick.index), y1: top, y2: volumeTop + volumeHeight }),
|
|
1898
|
+
h('text', {
|
|
1899
|
+
className: 'cwd-chartaxis',
|
|
1900
|
+
x: scaleX(tick.index),
|
|
1901
|
+
y: height - 5,
|
|
1902
|
+
textAnchor: tick.index === 0 ? 'start' : 'middle',
|
|
1903
|
+
}, tick.label))),
|
|
1904
|
+
// Volume first: candles read on top of the histogram, never the other way round.
|
|
1905
|
+
bars.map((bar, index) => {
|
|
1906
|
+
const barHeight = Math.max(0.5, scaleVolume(bar.volume))
|
|
1907
|
+
return h('rect', {
|
|
1908
|
+
key: `vol-${bar.date}`,
|
|
1909
|
+
className: bar.close >= bar.open ? 'cwd-vol-up' : 'cwd-vol-down',
|
|
1910
|
+
x: (scaleX(index) - barWidth / 2).toFixed(1),
|
|
1911
|
+
y: (volumeTop + volumeHeight - barHeight).toFixed(1),
|
|
1912
|
+
width: barWidth.toFixed(1),
|
|
1913
|
+
height: barHeight.toFixed(1),
|
|
1914
|
+
})
|
|
1915
|
+
}),
|
|
1916
|
+
h('text', { className: 'cwd-chartaxis', x: left - 8, y: volumeTop + 8, textAnchor: 'end' }, deskScaledText(maxVolume)),
|
|
1917
|
+
bars.map((bar, index) => {
|
|
1918
|
+
const open = scaleY(bar.open)
|
|
1919
|
+
const close = scaleY(bar.close)
|
|
1920
|
+
const bodyTop = Math.min(open, close)
|
|
1921
|
+
const bodyHeight = Math.max(0.8, Math.abs(close - open))
|
|
1922
|
+
return h('g', { key: `bar-${bar.date}`, className: bar.close >= bar.open ? 'cwd-candle-up' : 'cwd-candle-down' },
|
|
1923
|
+
h('line', {
|
|
1924
|
+
x1: scaleX(index).toFixed(1),
|
|
1925
|
+
x2: scaleX(index).toFixed(1),
|
|
1926
|
+
y1: scaleY(bar.high).toFixed(1),
|
|
1927
|
+
y2: scaleY(bar.low).toFixed(1),
|
|
1928
|
+
}),
|
|
1929
|
+
h('rect', {
|
|
1930
|
+
x: (scaleX(index) - barWidth / 2).toFixed(1),
|
|
1931
|
+
y: bodyTop.toFixed(1),
|
|
1932
|
+
width: barWidth.toFixed(1),
|
|
1933
|
+
height: bodyHeight.toFixed(1),
|
|
1934
|
+
}))
|
|
1935
|
+
}),
|
|
1936
|
+
maSeries.map((series) => {
|
|
1937
|
+
const path = lineOf(series.values)
|
|
1938
|
+
return path === '' ? null : h('path', { key: `ma-${series.window}`, className: `cwd-maline cwd-ma${series.window}`, d: path })
|
|
1939
|
+
}),
|
|
1940
|
+
focus === null ? null : h('g', null,
|
|
1941
|
+
h('line', { className: 'cwd-chartcross', x1: focusX, x2: focusX, y1: top, y2: volumeTop + volumeHeight }),
|
|
1942
|
+
h('line', { className: 'cwd-chartcross', x1: left, x2: left + plotWidth, y1: focusY, y2: focusY })),
|
|
1943
|
+
),
|
|
1944
|
+
focus === null ? null : h('div', { className: 'cwd-charttip', style: { left: `${tipLeft}px` } },
|
|
1945
|
+
h('div', { className: 'cwd-charttiptime' }, focus.date),
|
|
1946
|
+
h('div', { className: `cwd-charttipprice ${deskToneOf(focusPct)}` },
|
|
1947
|
+
`${deskNumberText(focus.close)} ${deskPctText(focusPct)}`),
|
|
1948
|
+
h('div', { className: 'cwd-charttiprow' },
|
|
1949
|
+
h('span', null, t('desk.kOpen')), h('span', null, deskNumberText(focus.open)),
|
|
1950
|
+
h('span', null, t('desk.kHigh')), h('span', null, deskNumberText(focus.high))),
|
|
1951
|
+
h('div', { className: 'cwd-charttiprow' },
|
|
1952
|
+
h('span', null, t('desk.kLow')), h('span', null, deskNumberText(focus.low)),
|
|
1953
|
+
h('span', null, t('desk.kClose')), h('span', null, deskNumberText(focus.close))),
|
|
1954
|
+
h('div', { className: 'cwd-charttiprow' },
|
|
1955
|
+
h('span', null, t('desk.trendVolume')), h('span', null, deskVolumeText(focus.volume, data.volume_unit, t)))))
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
/** Sidebar glyph: an axis plus a rising line reads as quotes without inventing a wallet/pie shape. */
|
|
1959
|
+
function WatchlistDeskIcon({ size = 18 }) {
|
|
1960
|
+
return h('svg', {
|
|
1961
|
+
width: size,
|
|
1962
|
+
height: size,
|
|
1963
|
+
viewBox: '0 0 24 24',
|
|
1964
|
+
fill: 'none',
|
|
1965
|
+
stroke: 'currentColor',
|
|
1966
|
+
strokeWidth: 1.8,
|
|
1967
|
+
strokeLinecap: 'round',
|
|
1968
|
+
strokeLinejoin: 'round',
|
|
1969
|
+
'aria-hidden': 'true',
|
|
1970
|
+
},
|
|
1971
|
+
h('path', { d: 'M4 19V5' }),
|
|
1972
|
+
h('path', { d: 'M4 19h16' }),
|
|
1973
|
+
h('path', { d: 'm7 15 3-4 3 2 5-7' }),
|
|
1974
|
+
h('circle', { cx: 18, cy: 6, r: 1.4, fill: 'currentColor', stroke: 'none' }))
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
function WatchlistDeskPage({ t }) {
|
|
1978
|
+
const [items, setItems] = useState([])
|
|
1979
|
+
const [loading, setLoading] = useState(true)
|
|
1980
|
+
const [refreshing, setRefreshing] = useState(false)
|
|
1981
|
+
const [refreshedAt, setRefreshedAt] = useState(null)
|
|
1982
|
+
const [failures, setFailures] = useState({})
|
|
1983
|
+
const [error, setError] = useState(null)
|
|
1984
|
+
const [groups, setGroups] = useState(readDeskGroups)
|
|
1985
|
+
const [activeGroup, setActiveGroup] = useState(DESK_ALL)
|
|
1986
|
+
const [groupOpen, setGroupOpen] = useState(false)
|
|
1987
|
+
const [newGroup, setNewGroup] = useState('')
|
|
1988
|
+
const [query, setQuery] = useState('')
|
|
1989
|
+
const [selected, setSelected] = useState(null)
|
|
1990
|
+
const [pendingRemove, setPendingRemove] = useState(null)
|
|
1991
|
+
const [rowMenu, setRowMenu] = useState(null)
|
|
1992
|
+
const [trend, setTrend] = useState({ status: 'idle', data: null, code: null })
|
|
1993
|
+
const [kline, setKline] = useState({ status: 'idle', data: null, code: null })
|
|
1994
|
+
// Folded = the intraday pane keeps only its title row, so the daily pane gets the whole column.
|
|
1995
|
+
const [trendFolded, setTrendFolded] = useState(false)
|
|
1996
|
+
const alive = useRef(true)
|
|
1997
|
+
|
|
1998
|
+
useEffect(() => {
|
|
1999
|
+
alive.current = true
|
|
2000
|
+
return () => { alive.current = false }
|
|
2001
|
+
}, [])
|
|
2002
|
+
useEffect(() => { writeDeskGroups(groups) }, [groups])
|
|
2003
|
+
|
|
2004
|
+
/** One refresh reply feeds the list, per-row failure marks and the footer time. */
|
|
2005
|
+
const applyRefresh = (payload) => {
|
|
2006
|
+
const landed = cleanRows(payload.items)
|
|
2007
|
+
if (Array.isArray(landed)) setItems(landed)
|
|
2008
|
+
const next = {}
|
|
2009
|
+
for (const item of payload.failures ?? []) {
|
|
2010
|
+
if (item !== null && typeof item === 'object' && typeof item.thscode === 'string') next[item.thscode] = item.code
|
|
2011
|
+
}
|
|
2012
|
+
setFailures(next)
|
|
2013
|
+
if (typeof payload.refreshed_at === 'number') setRefreshedAt(payload.refreshed_at)
|
|
2014
|
+
setError(payload.error !== undefined && payload.error !== null && typeof payload.error.code === 'string' ? payload.error.code : null)
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
/**
|
|
2018
|
+
* The series follows the selection: one request per click (the host caches it for a minute),
|
|
2019
|
+
* no polling and no prefetch. A stale answer is dropped by sequence, not merged.
|
|
2020
|
+
*/
|
|
2021
|
+
const loadTrend = async (thscode, options = {}) => {
|
|
2022
|
+
if (typeof thscode !== 'string' || thscode.length === 0) {
|
|
2023
|
+
setTrend({ status: 'idle', data: null, code: null })
|
|
2024
|
+
setKline({ status: 'idle', data: null, code: null })
|
|
2025
|
+
return
|
|
2026
|
+
}
|
|
2027
|
+
const request = (deskTrendSequence += 1)
|
|
2028
|
+
setTrend((previous) => ({ status: 'loading', data: previous.data !== null && previous.data.thscode === thscode ? previous.data : null, code: null }))
|
|
2029
|
+
try {
|
|
2030
|
+
const query = `thscode=${encodeURIComponent(thscode)}${options.bust === true ? '&refresh=1' : ''}`
|
|
2031
|
+
const payload = await call('/trend', { query })
|
|
2032
|
+
if (!alive.current || request !== deskTrendSequence) return
|
|
2033
|
+
setTrend({ status: 'ready', data: payload, code: null })
|
|
2034
|
+
} catch (failure) {
|
|
2035
|
+
if (!alive.current || request !== deskTrendSequence) return
|
|
2036
|
+
const code = typeof failure?.code === 'string' ? failure.code : 'trend_unavailable'
|
|
2037
|
+
setTrend({ status: code === 'trend_unavailable' ? 'unavailable' : 'error', data: null, code })
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
/** Same shape as `loadTrend`: the daily pane has its own request, so one slow history never blocks a tick. */
|
|
2042
|
+
const loadKline = async (thscode, options = {}) => {
|
|
2043
|
+
if (typeof thscode !== 'string' || thscode.length === 0) {
|
|
2044
|
+
setKline({ status: 'idle', data: null, code: null })
|
|
2045
|
+
return
|
|
2046
|
+
}
|
|
2047
|
+
const request = (deskKlineSequence += 1)
|
|
2048
|
+
setKline((previous) => ({ status: 'loading', data: previous.data !== null && previous.data.thscode === thscode ? previous.data : null, code: null }))
|
|
2049
|
+
try {
|
|
2050
|
+
const query = `thscode=${encodeURIComponent(thscode)}${options.bust === true ? '&refresh=1' : ''}`
|
|
2051
|
+
const payload = await call('/kline', { query })
|
|
2052
|
+
if (!alive.current || request !== deskKlineSequence) return
|
|
2053
|
+
setKline({ status: 'ready', data: payload, code: null })
|
|
2054
|
+
} catch (failure) {
|
|
2055
|
+
if (!alive.current || request !== deskKlineSequence) return
|
|
2056
|
+
const code = typeof failure?.code === 'string' ? failure.code : 'kline_unavailable'
|
|
2057
|
+
setKline({ status: code === 'kline_unavailable' ? 'unavailable' : 'error', data: null, code })
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
const selectRow = (thscode) => {
|
|
2062
|
+
setSelected(thscode)
|
|
2063
|
+
void loadTrend(thscode)
|
|
2064
|
+
void loadKline(thscode)
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
// Opening the panel is the user request: read the list, then quote it once. No polling.
|
|
2068
|
+
useEffect(() => {
|
|
2069
|
+
let cancelled = false
|
|
2070
|
+
const boot = async () => {
|
|
2071
|
+
try {
|
|
2072
|
+
const listed = await call('/list')
|
|
2073
|
+
if (cancelled) return
|
|
2074
|
+
const landed = cleanRows(listed.items) ?? []
|
|
2075
|
+
setItems(landed)
|
|
2076
|
+
// The detail panel is the main area: start on the first symbol instead of an empty aside.
|
|
2077
|
+
const first = typeof landed[0]?.thscode === 'string' ? landed[0].thscode : null
|
|
2078
|
+
setSelected((value) => (value !== null ? value : first))
|
|
2079
|
+
if (first !== null) {
|
|
2080
|
+
void loadTrend(first)
|
|
2081
|
+
void loadKline(first)
|
|
2082
|
+
}
|
|
2083
|
+
} catch (failure) {
|
|
2084
|
+
if (!cancelled) setError(failure.code ?? 'load_failed')
|
|
2085
|
+
return
|
|
2086
|
+
} finally {
|
|
2087
|
+
if (!cancelled) setLoading(false)
|
|
2088
|
+
}
|
|
2089
|
+
try {
|
|
2090
|
+
const payload = await call('/refresh', { body: {} })
|
|
2091
|
+
if (!cancelled) applyRefresh(payload)
|
|
2092
|
+
} catch (failure) {
|
|
2093
|
+
if (!cancelled) setError(failure.code ?? 'fuyao_unavailable')
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
void boot()
|
|
2097
|
+
return () => { cancelled = true }
|
|
2098
|
+
}, [])
|
|
2099
|
+
|
|
2100
|
+
const refresh = async () => {
|
|
2101
|
+
if (refreshing) return
|
|
2102
|
+
setRefreshing(true)
|
|
2103
|
+
try {
|
|
2104
|
+
const payload = await call('/refresh', { body: {} })
|
|
2105
|
+
if (alive.current) applyRefresh(payload)
|
|
2106
|
+
if (alive.current && selected !== null) {
|
|
2107
|
+
void loadTrend(selected, { bust: true })
|
|
2108
|
+
void loadKline(selected, { bust: true })
|
|
2109
|
+
}
|
|
2110
|
+
} catch (failure) {
|
|
2111
|
+
if (alive.current) setError(failure.code ?? 'fuyao_unavailable')
|
|
2112
|
+
} finally {
|
|
2113
|
+
if (alive.current) setRefreshing(false)
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
const removeRow = async (thscode) => {
|
|
2118
|
+
const before = items
|
|
2119
|
+
setPendingRemove(null)
|
|
2120
|
+
setItems(before.filter((row) => row.thscode !== thscode))
|
|
2121
|
+
if (selected === thscode) {
|
|
2122
|
+
setSelected(null)
|
|
2123
|
+
setTrend({ status: 'idle', data: null, code: null })
|
|
2124
|
+
}
|
|
2125
|
+
try {
|
|
2126
|
+
await call('/remove', { body: { thscode } })
|
|
2127
|
+
} catch {
|
|
2128
|
+
// Put the row back exactly where it was; the host never confirmed the removal.
|
|
2129
|
+
if (alive.current) setItems(before)
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
const pinRow = async (thscode) => {
|
|
2134
|
+
const before = items
|
|
2135
|
+
const target = before.find((row) => row.thscode === thscode)
|
|
2136
|
+
if (target === undefined) return
|
|
2137
|
+
setItems([target, ...before.filter((row) => row.thscode !== thscode)])
|
|
2138
|
+
try {
|
|
2139
|
+
const payload = await call('/pin', { body: { thscode } })
|
|
2140
|
+
if (Array.isArray(payload.items) && alive.current) setItems(cleanRows(payload.items))
|
|
2141
|
+
} catch {
|
|
2142
|
+
if (alive.current) setItems(before)
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
const createGroup = () => {
|
|
2147
|
+
const name = newGroup.trim()
|
|
2148
|
+
if (name.length === 0 || name === DESK_ALL || groups.names.includes(name)) return
|
|
2149
|
+
setGroups({ names: [...groups.names, name], assignments: groups.assignments })
|
|
2150
|
+
setNewGroup('')
|
|
2151
|
+
setActiveGroup(name)
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
const deleteGroup = (name) => {
|
|
2155
|
+
if (name === DESK_ALL) return
|
|
2156
|
+
const assignments = {}
|
|
2157
|
+
for (const [thscode, names] of Object.entries(groups.assignments)) {
|
|
2158
|
+
const kept = (Array.isArray(names) ? names : []).filter((entry) => entry !== name)
|
|
2159
|
+
if (kept.length > 0) assignments[thscode] = kept
|
|
2160
|
+
}
|
|
2161
|
+
setGroups({ names: groups.names.filter((entry) => entry !== name), assignments })
|
|
2162
|
+
setActiveGroup(DESK_ALL)
|
|
2163
|
+
setGroupOpen(false)
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
const toggleGroup = (thscode, name) => {
|
|
2167
|
+
const current = deskGroupsOf(groups, thscode)
|
|
2168
|
+
const next = current.includes(name) ? current.filter((entry) => entry !== name) : [...current, name]
|
|
2169
|
+
const assignments = { ...groups.assignments }
|
|
2170
|
+
if (next.length === 0) delete assignments[thscode]
|
|
2171
|
+
else assignments[thscode] = next
|
|
2172
|
+
setGroups({ names: groups.names, assignments })
|
|
2173
|
+
}
|
|
2174
|
+
|
|
2175
|
+
const term = query.trim().toLowerCase()
|
|
2176
|
+
const visible = items.filter((item) => {
|
|
2177
|
+
if (activeGroup !== DESK_ALL && !deskGroupsOf(groups, item.thscode).includes(activeGroup)) return false
|
|
2178
|
+
if (term.length === 0) return true
|
|
2179
|
+
return [item.name, item.thscode, item.ticker].some((value) => typeof value === 'string' && value.toLowerCase().includes(term))
|
|
2180
|
+
})
|
|
2181
|
+
const current = selected === null ? null : (items.find((item) => item.thscode === selected) ?? null)
|
|
2182
|
+
|
|
2183
|
+
const groupMenuItems = [{ id: DESK_ALL, label: t('desk.allGroups'), icon: activeGroup === DESK_ALL ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined }]
|
|
2184
|
+
.concat(groups.names.map((name) => ({ id: name, label: name, icon: activeGroup === name ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined })))
|
|
2185
|
+
|
|
2186
|
+
// The row you are looking at is the freshest thing in the panel: once its intraday payload lands,
|
|
2187
|
+
// the list shows that price too, so one instrument never carries two numbers on the same screen.
|
|
2188
|
+
const liveQuote = (item) => {
|
|
2189
|
+
if (trend.status !== 'ready' || trend.data === null || trend.data.thscode !== item.thscode || typeof trend.data.last !== 'number') return item.quote
|
|
2190
|
+
const prevClose = trend.data.prev_close
|
|
2191
|
+
return { price: trend.data.last, change_pct: prevClose > 0 ? ((trend.data.last - prevClose) / prevClose) * 100 : null }
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
const rows = visible.map((item, index) => {
|
|
2195
|
+
const quote = liveQuote(item)
|
|
2196
|
+
const pct = deskPctOf(quote)
|
|
2197
|
+
const failure = failures[item.thscode]
|
|
2198
|
+
const names = deskGroupsOf(groups, item.thscode)
|
|
2199
|
+
const isSelected = selected === item.thscode
|
|
2200
|
+
const quoteTitle = failure === undefined ? undefined : t(`error.${failure}`)
|
|
2201
|
+
const menuOpen = rowMenu === item.thscode
|
|
2202
|
+
return h('div', {
|
|
2203
|
+
key: item.thscode,
|
|
2204
|
+
className: 'cwd-row',
|
|
2205
|
+
role: 'listitem',
|
|
2206
|
+
'aria-current': isSelected ? 'true' : undefined,
|
|
2207
|
+
onClick: (event) => { if (event.target.closest('.cwd-rowactions') === null) selectRow(item.thscode) },
|
|
2208
|
+
},
|
|
2209
|
+
h('button', {
|
|
2210
|
+
type: 'button',
|
|
2211
|
+
className: 'cwd-cellname',
|
|
2212
|
+
'aria-pressed': isSelected,
|
|
2213
|
+
onClick: () => selectRow(item.thscode),
|
|
2214
|
+
},
|
|
2215
|
+
h('span', { className: 'cwd-nameline' },
|
|
2216
|
+
h('span', { className: 'cwd-nametext', title: item.name }, scrubInvisible(item.name)),
|
|
2217
|
+
h(TypeTag, { assetType: item.asset_type, t })),
|
|
2218
|
+
h('span', { className: 'cwd-codeline' }, h('span', { className: 'cwd-code' }, item.thscode))),
|
|
2219
|
+
h('div', { className: failure === undefined ? 'cwd-price' : 'cwd-price cwd-stale', title: quoteTitle }, deskPriceText(quote)),
|
|
2220
|
+
h('div', { className: `cwd-pct ${deskToneOf(pct)}`, title: quoteTitle }, deskPctText(pct)),
|
|
2221
|
+
// One trigger per row: pin, group checkboxes and remove live in the official Menu.
|
|
2222
|
+
h('div', { className: 'cwd-rowactions' },
|
|
2223
|
+
h(Menu, {
|
|
2224
|
+
open: menuOpen,
|
|
2225
|
+
anchor: h('button', {
|
|
2226
|
+
type: 'button',
|
|
2227
|
+
className: 'cwd-iconbtn',
|
|
2228
|
+
title: t('desk.more'),
|
|
2229
|
+
'aria-label': `${t('desk.more')} ${item.name}`,
|
|
2230
|
+
'aria-haspopup': 'menu',
|
|
2231
|
+
'aria-expanded': menuOpen,
|
|
2232
|
+
onClick: () => { setPendingRemove(null); setRowMenu(menuOpen ? null : item.thscode) },
|
|
2233
|
+
}, h(IconEllipsisOutlineRegular, { size: 16 })),
|
|
2234
|
+
items: [{ id: 'pin', label: t('desk.pin'), icon: h(IconPinOutlineRegular, { size: 14 }), disabled: index === 0 }],
|
|
2235
|
+
children: [
|
|
2236
|
+
...(groups.names.length === 0
|
|
2237
|
+
? [h('div', { key: 'no-group', className: 'cwd-menuhint' }, t('desk.noGroupYet'))]
|
|
2238
|
+
: groups.names.map((name) => h(MenuItemButton, {
|
|
2239
|
+
key: `group:${name}`,
|
|
2240
|
+
icon: names.includes(name) ? h(IconChecklistOutlineRegular, { size: 14 }) : undefined,
|
|
2241
|
+
onSelect: () => toggleGroup(item.thscode, name),
|
|
2242
|
+
}, name))),
|
|
2243
|
+
h(MenuItemButton, {
|
|
2244
|
+
key: 'remove',
|
|
2245
|
+
danger: true,
|
|
2246
|
+
separatorBefore: true,
|
|
2247
|
+
icon: h(IconTrashOutlineRegular, { size: 14 }),
|
|
2248
|
+
onSelect: () => { setRowMenu(null); setPendingRemove(item) },
|
|
2249
|
+
}, t('desk.remove')),
|
|
2250
|
+
],
|
|
2251
|
+
onSelect: (id) => {
|
|
2252
|
+
if (id !== 'pin') return
|
|
2253
|
+
setRowMenu(null)
|
|
2254
|
+
void pinRow(item.thscode)
|
|
2255
|
+
},
|
|
2256
|
+
onClose: () => setRowMenu(null),
|
|
2257
|
+
align: 'end',
|
|
2258
|
+
portal: true,
|
|
2259
|
+
listClassName: 'cwd-menulist',
|
|
2260
|
+
}))
|
|
2261
|
+
)
|
|
2262
|
+
})
|
|
2263
|
+
|
|
2264
|
+
const listBody = loading
|
|
2265
|
+
? h('div', { className: 'cwd-empty' }, h('div', { className: 'cwd-emptytitle' }, t('desk.loading')))
|
|
2266
|
+
: items.length === 0
|
|
2267
|
+
? h('div', { className: 'cwd-empty' }, h('div', { className: 'cwd-emptytitle' }, t('desk.empty')), h('p', { className: 'cwd-emptyhint' }, t('desk.emptyHint')))
|
|
2268
|
+
: visible.length === 0
|
|
2269
|
+
? h('div', { className: 'cwd-empty' }, h('div', { className: 'cwd-emptytitle' }, t('desk.noMatch')), h('p', { className: 'cwd-emptyhint' }, t('desk.noMatchHint')))
|
|
2270
|
+
: h('div', { className: 'cwd-tablebody', role: 'list', 'aria-label': t('desk.title') }, rows)
|
|
2271
|
+
|
|
2272
|
+
|
|
2273
|
+
// The block note states the session fact (live / closed / previous) and the clock the axis uses.
|
|
2274
|
+
const trendData = trend.status === 'ready' ? trend.data : null
|
|
2275
|
+
// The chart is fetched later than the list, so for the selected row it is the fresher vintage:
|
|
2276
|
+
// the headline price, its percentage and the as-of stamp all come from the same series as the
|
|
2277
|
+
// pane below, instead of ageing by every minute the panel sits idle.
|
|
2278
|
+
const trendOwns = trendData !== null && current !== null && trendData.thscode === current.thscode && typeof trendData.last === 'number'
|
|
2279
|
+
const detailQuote = current === null ? null : liveQuote(current)
|
|
2280
|
+
const detailPct = deskPctOf(detailQuote)
|
|
2281
|
+
const detailPrint = trendOwns ? trendData.points[trendData.points.length - 1][0] : null
|
|
2282
|
+
// One clock on the panel: when the number above was printed. The zone suffix only appears when
|
|
2283
|
+
// that clock is not the reader's own (the US session runs on ET); A-share and HK print on it.
|
|
2284
|
+
const printZone = trendOwns && trendData.market === 'us' ? ` ${t('desk.trendZoneUs')}` : ''
|
|
2285
|
+
const detailAt = trendOwns
|
|
2286
|
+
? `${String(trendData.session_date ?? '').slice(5)} ${detailPrint}${printZone}`.trim()
|
|
2287
|
+
: current === null || current.quote === null || current.quote === undefined ? t('desk.notRefreshed') : (formatTime(current.quote.captured_at) || t('desk.notRefreshed'))
|
|
2288
|
+
const trendZone = trendData === null || trendData.market === 'a-share' ? '' : ` ${t(trendData.market === 'us' ? 'desk.trendZoneUs' : 'desk.trendZoneHk')}`
|
|
2289
|
+
const trendNote = trendData === null
|
|
2290
|
+
? (trend.status === 'loading' ? t('desk.trendLoading') : trend.status === 'error' ? t('desk.trendError') : '')
|
|
2291
|
+
: trendData.session_status === 'live'
|
|
2292
|
+
? `${trendData.stale ? t('desk.trendStale') : t('desk.trendLive')}${trendZone} · ${trendData.points[trendData.points.length - 1][0]}`
|
|
2293
|
+
: trendData.session_status === 'closed'
|
|
2294
|
+
? `${trendData.session_date ?? ''} ${t('desk.trendClosed')}${trendZone}`
|
|
2295
|
+
: `${t('desk.trendPrevious')} ${trendData.session_date ?? ''}${trendZone}`
|
|
2296
|
+
|
|
2297
|
+
const trendStats = trendData === null ? null : h('div', { className: 'cwd-trendstats' },
|
|
2298
|
+
...[
|
|
2299
|
+
[t('desk.trendOpen'), deskNumberText(trendData.open)],
|
|
2300
|
+
[t('desk.trendHigh'), deskNumberText(trendData.high)],
|
|
2301
|
+
[t('desk.trendLow'), deskNumberText(trendData.low)],
|
|
2302
|
+
[t('desk.trendAvg'), deskNumberText(trendData.avg)],
|
|
2303
|
+
[t('desk.trendVolume'), deskVolumeText(trendData.volume, trendData.volume_unit, t)],
|
|
2304
|
+
[t('desk.trendAmount'), deskAmountText(trendData.amount, trendData.currency)],
|
|
2305
|
+
].map(([label, value]) => h('div', { key: label, className: 'cwd-trendstat' },
|
|
2306
|
+
h('span', null, label), h('span', { title: value }, value))))
|
|
2307
|
+
|
|
2308
|
+
const trendBody = trendData !== null
|
|
2309
|
+
? h(IntradayChart, { key: trendData.thscode, data: trendData, t })
|
|
2310
|
+
: h('div', { className: 'cwd-chart' }, h('div', null,
|
|
2311
|
+
h('div', { className: 'cwd-charttext' }, trend.status === 'error' ? t('desk.trendError') : trend.status === 'loading' ? t('desk.trendLoading') : t('desk.trendUnavailable')),
|
|
2312
|
+
trend.status === 'unavailable'
|
|
2313
|
+
? h('div', { className: 'cwd-charthint' }, t('desk.trendUnavailableHint'))
|
|
2314
|
+
: null,
|
|
2315
|
+
trend.status === 'error'
|
|
2316
|
+
? h('button', { type: 'button', className: 'cwd-pill', onClick: () => { void loadTrend(selected, { bust: true }) } }, t('desk.trendRetry'))
|
|
2317
|
+
: null))
|
|
2318
|
+
const klineData = kline.status === 'ready' && Array.isArray(kline.data?.bars) && kline.data.bars.length > 0 ? kline.data : null
|
|
2319
|
+
const klineNote = klineData === null
|
|
2320
|
+
? (kline.status === 'loading' ? t('desk.klineLoading') : kline.status === 'error' ? t('desk.klineError') : '')
|
|
2321
|
+
: t('desk.adjustQfq')
|
|
2322
|
+
// The legend reads the same series the paths draw, so the numbers and the lines cannot disagree.
|
|
2323
|
+
const klineLegend = klineData === null ? null : h('div', { className: 'cwd-malegend' },
|
|
2324
|
+
...MA_WINDOWS.map((window) => {
|
|
2325
|
+
const values = movingAverage(klineData.bars, window)
|
|
2326
|
+
const last = values[values.length - 1]
|
|
2327
|
+
return h('span', { key: window, className: `cwd-malegenditem cwd-ma${window}` }, `MA${window} ${last === null || last === undefined ? '—' : deskNumberText(last)}`)
|
|
2328
|
+
}))
|
|
2329
|
+
const klineBody = klineData !== null
|
|
2330
|
+
? h(DailyChart, { key: klineData.thscode, data: klineData, t })
|
|
2331
|
+
: h('div', { className: 'cwd-chart' }, h('div', null,
|
|
2332
|
+
h('div', { className: 'cwd-charttext' }, kline.status === 'error' ? t('desk.klineError') : kline.status === 'loading' ? t('desk.klineLoading') : t('desk.klineUnavailable')),
|
|
2333
|
+
kline.status === 'unavailable' ? h('div', { className: 'cwd-charthint' }, t('desk.klineUnavailableHint')) : null,
|
|
2334
|
+
kline.status === 'error'
|
|
2335
|
+
? h('button', { type: 'button', className: 'cwd-pill', onClick: () => { void loadKline(selected, { bust: true }) } }, t('desk.trendRetry'))
|
|
2336
|
+
: null))
|
|
2337
|
+
const klineBlock = h('div', { className: 'cwd-block cwd-block-kline' },
|
|
2338
|
+
h('div', { className: 'cwd-blockhead' },
|
|
2339
|
+
h('span', { className: 'cwd-blocktitle' }, t('desk.daily')),
|
|
2340
|
+
klineLegend,
|
|
2341
|
+
h('span', { className: 'cwd-blocknote' }, klineNote)),
|
|
2342
|
+
klineBody)
|
|
2343
|
+
|
|
2344
|
+
const detail = current === null
|
|
2345
|
+
? h('div', { className: 'cwd-card' }, h('div', { className: 'cwd-empty' },
|
|
2346
|
+
h('div', { className: 'cwd-emptytitle' }, t('desk.selectHint')),
|
|
2347
|
+
h('p', { className: 'cwd-emptyhint' }, t('desk.selectHintBody'))))
|
|
2348
|
+
: h('div', { className: 'cwd-card' }, h('div', { className: 'cwd-detail' },
|
|
2349
|
+
h('div', { className: 'cwd-detailhead' },
|
|
2350
|
+
h('div', { style: { minWidth: 0 } },
|
|
2351
|
+
h('div', { className: 'cwd-detailname' },
|
|
2352
|
+
h('span', { className: 'cwd-detailtext', title: current.name }, scrubInvisible(current.name)),
|
|
2353
|
+
h(TypeTag, { assetType: current.asset_type, t })),
|
|
2354
|
+
h('div', { className: 'cwd-detailcode' }, current.thscode))),
|
|
2355
|
+
// The price row owns the right half of the header: two facts sit beside it instead of under it,
|
|
2356
|
+
// which is what buys both panes their height back.
|
|
2357
|
+
h('div', { className: 'cwd-quoterow' },
|
|
2358
|
+
h('div', { className: 'cwd-bigquote' },
|
|
2359
|
+
h('span', { className: 'cwd-bigprice' }, deskPriceText(detailQuote)),
|
|
2360
|
+
h('span', { className: `cwd-bigpct ${deskToneOf(detailPct)}` }, deskPctText(detailPct))),
|
|
2361
|
+
h('div', { className: 'cwd-meta' },
|
|
2362
|
+
h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.capturedAt')), h('div', { className: 'cwd-metavalue' }, detailAt)),
|
|
2363
|
+
h('div', { className: 'cwd-metaitem' }, h('div', { className: 'cwd-metalabel' }, t('desk.kind')), h('div', { className: 'cwd-metavalue' }, typeLabel(current.asset_type, t))))),
|
|
2364
|
+
h('div', { className: trendFolded ? 'cwd-block cwd-block-chart cwd-folded' : 'cwd-block cwd-block-chart' },
|
|
2365
|
+
h('div', { className: 'cwd-blockhead' },
|
|
2366
|
+
h('span', { className: 'cwd-blocktitle' }, t('desk.intraday')),
|
|
2367
|
+
trendFolded ? null : trendStats,
|
|
2368
|
+
h('span', { className: 'cwd-blocknote' }, trendNote),
|
|
2369
|
+
// Two panes in one column: folding the upper one hands the height to the daily pane instead
|
|
2370
|
+
// of pushing the card into a scrollbar.
|
|
2371
|
+
h('button', {
|
|
2372
|
+
type: 'button',
|
|
2373
|
+
className: 'cwd-blockfold',
|
|
2374
|
+
'aria-expanded': trendFolded ? 'false' : 'true',
|
|
2375
|
+
onClick: () => setTrendFolded(!trendFolded),
|
|
2376
|
+
}, trendFolded ? t('desk.unfold') : t('desk.fold'))),
|
|
2377
|
+
trendFolded ? null : trendBody),
|
|
2378
|
+
klineBlock))
|
|
2379
|
+
|
|
2380
|
+
return h('div', { className: 'cwd-page' },
|
|
2381
|
+
h('div', { className: 'cwd-inner' },
|
|
2382
|
+
h('header', { className: 'cwd-head' },
|
|
2383
|
+
h('h1', { className: 'cwd-title' }, t('desk.title')),
|
|
2384
|
+
h('div', { className: 'cwd-headactions' },
|
|
2385
|
+
h('span', { className: 'cwd-updated' },
|
|
2386
|
+
`${t('desk.lastUpdate')} ${refreshedAt === null ? t('desk.notRefreshed') : formatTime(refreshedAt)}`),
|
|
2387
|
+
h('button', { type: 'button', className: 'cwd-refresh', disabled: refreshing, onClick: () => { void refresh() } },
|
|
2388
|
+
h(IconRefreshOutlineRegular, { size: 14 }),
|
|
2389
|
+
refreshing ? t('desk.refreshing') : t('desk.refresh')))),
|
|
2390
|
+
h('div', { className: 'cwd-body' },
|
|
2391
|
+
h('section', { className: 'cwd-card' },
|
|
2392
|
+
h('div', { className: 'cwd-toolbar' },
|
|
2393
|
+
h('label', { className: 'cwd-field' },
|
|
2394
|
+
h(IconSearchOutlineRegular, { size: 14 }),
|
|
2395
|
+
h('input', { type: 'text', value: query, placeholder: t('desk.filterPlaceholder'), 'aria-label': t('desk.filter'), onChange: (event) => setQuery(event.target.value) })),
|
|
2396
|
+
h(Menu, {
|
|
2397
|
+
open: groupOpen,
|
|
2398
|
+
anchor: h('button', {
|
|
2399
|
+
type: 'button',
|
|
2400
|
+
className: 'cwd-pill',
|
|
2401
|
+
'aria-haspopup': 'menu',
|
|
2402
|
+
'aria-expanded': groupOpen,
|
|
2403
|
+
'aria-label': t('desk.group'),
|
|
2404
|
+
onClick: () => setGroupOpen(!groupOpen),
|
|
2405
|
+
}, h(IconGoalOutlineRegular, { size: 14 }), h('span', null, activeGroup === DESK_ALL ? t('desk.allGroups') : activeGroup)),
|
|
2406
|
+
items: groupMenuItems,
|
|
2407
|
+
children: activeGroup === DESK_ALL ? [] : [h(MenuItemButton, {
|
|
2408
|
+
key: 'delete-group',
|
|
2409
|
+
danger: true,
|
|
2410
|
+
separatorBefore: true,
|
|
2411
|
+
icon: h(IconTrashOutlineRegular, { size: 14 }),
|
|
2412
|
+
onSelect: () => deleteGroup(activeGroup),
|
|
2413
|
+
}, t('desk.deleteGroup'))],
|
|
2414
|
+
onSelect: (id) => { setGroupOpen(false); setActiveGroup(id) },
|
|
2415
|
+
onClose: () => setGroupOpen(false),
|
|
2416
|
+
align: 'start',
|
|
2417
|
+
portal: true,
|
|
2418
|
+
listClassName: 'cwd-menulist',
|
|
2419
|
+
}),
|
|
2420
|
+
h('div', { className: 'cwd-groupcreate' },
|
|
2421
|
+
h('input', {
|
|
2422
|
+
type: 'text',
|
|
2423
|
+
value: newGroup,
|
|
2424
|
+
maxLength: 20,
|
|
2425
|
+
placeholder: t('desk.newGroup'),
|
|
2426
|
+
'aria-label': t('desk.newGroup'),
|
|
2427
|
+
onChange: (event) => setNewGroup(event.target.value),
|
|
2428
|
+
onKeyDown: (event) => { if (event.key === 'Enter') createGroup() },
|
|
2429
|
+
}),
|
|
2430
|
+
h('button', { type: 'button', className: 'cwd-pill', disabled: newGroup.trim().length === 0, onClick: createGroup }, t('desk.createGroup')))),
|
|
2431
|
+
error === null ? null : h('div', { className: 'cwd-error', role: 'alert' }, error === 'load_failed' ? t('desk.loadFailed') : t(`error.${error}`)),
|
|
2432
|
+
pendingRemove === null ? null : h('div', { className: 'cwd-notice cwd-notice-danger' },
|
|
2433
|
+
h('span', null, `${t('desk.removeHint')} · ${scrubInvisible(pendingRemove.name)}`),
|
|
2434
|
+
h('button', { type: 'button', className: 'cwd-pill', onClick: () => setPendingRemove(null) }, t('desk.cancel'))),
|
|
2435
|
+
h('div', { className: 'cwd-thead', role: 'row' },
|
|
2436
|
+
h('span', null, t('desk.colName')),
|
|
2437
|
+
h('span', { className: 'cwd-right' }, t('desk.colPrice')),
|
|
2438
|
+
h('span', { className: 'cwd-right' }, t('desk.colChange')),
|
|
2439
|
+
h('span', { className: 'cwd-right' }, t('desk.colAction'))),
|
|
2440
|
+
listBody),
|
|
2441
|
+
h('aside', null, detail)),
|
|
2442
|
+
))
|
|
2443
|
+
}
|
|
2444
|
+
|
|
1234
2445
|
function apply(ctx) {
|
|
1235
2446
|
ctx.effect(installStyles, `${ENTRY_NAME}: styles`)
|
|
1236
2447
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), `${ENTRY_NAME}: dictionaries`)
|
|
@@ -1280,6 +2491,23 @@ function apply(ctx) {
|
|
|
1280
2491
|
},
|
|
1281
2492
|
}, WatchlistDialog))
|
|
1282
2493
|
|
|
2494
|
+
// Desk shell: one sidebar entry + its main panel. Quotes still come from the host
|
|
2495
|
+
// route the dialog uses; the page never fetches anything the dialog would not.
|
|
2496
|
+
// Registered after the overlay so the dialog stays the first seat this plugin adds.
|
|
2497
|
+
const deskT = ctx.locale.bind(NS)
|
|
2498
|
+
ctx.slots.inject('main', () => ctx.slots.register({
|
|
2499
|
+
name: 'main',
|
|
2500
|
+
key: DESK_PANEL_ID,
|
|
2501
|
+
locale: NS,
|
|
2502
|
+
}, WatchlistDeskPage))
|
|
2503
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({
|
|
2504
|
+
name: 'sidebar.panellist',
|
|
2505
|
+
id: DESK_PANEL_ID,
|
|
2506
|
+
order: 12,
|
|
2507
|
+
locale: NS,
|
|
2508
|
+
label: () => deskT('desk.panel'),
|
|
2509
|
+
}, WatchlistDeskIcon))
|
|
2510
|
+
|
|
1283
2511
|
ctx.inject(['commandUi'], (scope) => {
|
|
1284
2512
|
const t = ctx.locale.bind(NS)
|
|
1285
2513
|
scope.effect(() => scope.commandUi.register({
|