dsh-xueqiu 1.0.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.
@@ -0,0 +1,854 @@
1
+ import * as React from 'react'
2
+
3
+ export default {
4
+
5
+ inject: ['timer', 'connection'],
6
+ apply(ctx) {
7
+ styles.insert('\n' +
8
+ '.xq-float{position:fixed;right:16px;bottom:16px;width:720px;max-width:92vw;max-height:82vh;display:flex;flex-direction:column;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l2);border-radius:12px;box-shadow:0 10px 40px rgba(0,0,0,.28);z-index:1200;pointer-events:auto;overflow:hidden;font-size:13px;line-height:1.45;color:var(--dsw-alias-label-primary);}\n' +
9
+ '.xq-float *{box-sizing:border-box;}\n' +
10
+ '.xq-title{display:flex;align-items:center;gap:8px;padding:8px 12px;border-bottom:1px solid var(--dsw-alias-border-l1);cursor:grab;user-select:none;flex-shrink:0;}\n' +
11
+ '.xq-title:active{cursor:grabbing;}\n' +
12
+ '.xq-min{cursor:pointer;width:auto;max-width:520px;flex-direction:row;align-items:center;gap:10px;padding:7px 12px;}\n' +
13
+ '.xq-body{overflow-y:auto;flex:1;padding:0 12px 10px;}\n' +
14
+ '.xq-entry{display:flex;align-items:center;gap:10px;cursor:pointer;width:100%;max-width:760px;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:10px;padding:7px 12px;}\n' +
15
+ '.xq-entry:hover{border-color:var(--dsw-alias-brand-primary);}\n' +
16
+ '.xq-entry *{box-sizing:border-box;}\n' +
17
+ '.xq-head{display:flex;align-items:center;gap:8px;margin-bottom:8px;}\n' +
18
+ '.xq-logo{font-weight:700;font-size:14px;letter-spacing:.5px;white-space:nowrap;}\n' +
19
+ '.xq-logo b{color:var(--dsw-alias-brand-primary);}\n' +
20
+ '.xq-update{font-size:11px;color:var(--dsw-alias-label-secondary);white-space:nowrap;}\n' +
21
+ '.xq-status{font-size:10px;padding:1px 6px;border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);white-space:nowrap;}\n' +
22
+ '.xq-status.xq-live{color:var(--dsw-alias-state-error-primary);}\n' +
23
+ '.xq-spacer{flex:1;}\n' +
24
+ '.xq-btn{font-size:12px;padding:2px 10px;border-radius:6px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);cursor:pointer;}\n' +
25
+ '.xq-btn:hover{border-color:var(--dsw-alias-brand-primary);}\n' +
26
+ '.xq-btn:disabled{opacity:.5;cursor:default;}\n' +
27
+ '.xq-btn-mini{font-size:11px;padding:1px 8px;border-radius:5px;border:1px solid var(--dsw-alias-border-l2);background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;line-height:1.4;}\n' +
28
+ '.xq-btn-mini:hover{color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-secondary);}\n' +
29
+ '.xq-tabs{display:flex;gap:4px;align-items:center;border-bottom:1px solid var(--dsw-alias-border-l1);margin-bottom:8px;}\n' +
30
+ '.xq-tab{font-size:13px;padding:5px 12px;border:none;background:none;color:var(--dsw-alias-label-secondary);cursor:pointer;border-bottom:2px solid transparent;}\n' +
31
+ '.xq-tab:hover{color:var(--dsw-alias-label-primary);}\n' +
32
+ '.xq-tab-active{color:var(--dsw-alias-brand-primary);border-bottom-color:var(--dsw-alias-brand-primary);font-weight:600;}\n' +
33
+ '.xq-idx{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:8px;}\n' +
34
+ '.xq-idx-card{flex:1;min-width:120px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:6px 8px;}\n' +
35
+ '.xq-idx-name{font-size:11px;color:var(--dsw-alias-label-secondary);}\n' +
36
+ '.xq-idx-row{display:flex;align-items:baseline;gap:6px;}\n' +
37
+ '.xq-idx-cur{font-size:14px;font-weight:700;}\n' +
38
+ '.xq-idx-pct{font-size:11px;}\n' +
39
+ '.xq-up{color:var(--dsw-alias-state-error-primary);}\n' +
40
+ '.xq-down{color:var(--dsw-alias-state-success-primary);}\n' +
41
+ '.xq-flat{color:var(--dsw-alias-label-secondary);}\n' +
42
+ '.xq-grid{display:grid;gap:0;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;overflow:hidden;margin-bottom:8px;}\n' +
43
+ '.xq-grid-hd,.xq-grid-row{display:grid;grid-template-columns:1.6fr 1fr 1fr 1fr 84px;align-items:center;}\n' +
44
+ '.xq-grid-hd{font-size:11px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-2);padding:5px 8px;}\n' +
45
+ '.xq-grid-row{padding:6px 8px;border-top:1px solid var(--dsw-alias-border-l1);cursor:pointer;font-size:12.5px;}\n' +
46
+ '.xq-grid-row:hover{background:var(--dsw-alias-bg-layer-2);}\n' +
47
+ '.xq-name{font-weight:600;}\n' +
48
+ '.xq-sub{font-size:10.5px;color:var(--dsw-alias-label-secondary);}\n' +
49
+ '.xq-muted{font-size:12px;color:var(--dsw-alias-label-secondary);}\n' +
50
+ '.xq-err{font-size:12px;color:var(--dsw-alias-state-warn-primary);background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:6px;padding:5px 8px;margin-bottom:6px;}\n' +
51
+ '.xq-actions{display:flex;gap:4px;justify-content:flex-end;}\n' +
52
+ '.xq-input{font-size:12.5px;padding:4px 8px;border-radius:6px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);}\n' +
53
+ '.xq-input:focus{outline:none;border-color:var(--dsw-alias-brand-primary);}\n' +
54
+ '.xq-search-row{display:flex;gap:6px;margin-bottom:8px;}\n' +
55
+ '.xq-search-row .xq-input{flex:1;}\n' +
56
+ '.xq-seg{display:inline-flex;gap:2px;border:1px solid var(--dsw-alias-border-l2);border-radius:6px;padding:1px;}\n' +
57
+ '.xq-seg button{font-size:11.5px;border:none;background:none;color:var(--dsw-alias-label-secondary);padding:2px 8px;border-radius:5px;cursor:pointer;}\n' +
58
+ '.xq-seg button.xq-seg-on{background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font-weight:600;}\n' +
59
+ '.xq-news{display:flex;flex-direction:column;gap:7px;max-height:380px;overflow-y:auto;}\n' +
60
+ '.xq-news-item{font-size:12.5px;padding:6px 8px;background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:7px;}\n' +
61
+ '.xq-news-item.xq-important{border-left:3px solid var(--dsw-alias-state-warn-primary);}\n' +
62
+ '.xq-news-time{font-size:10.5px;color:var(--dsw-alias-label-secondary);margin-top:3px;}\n' +
63
+ '.xq-detail-head{display:flex;align-items:center;gap:10px;margin-bottom:8px;flex-wrap:wrap;}\n' +
64
+ '.xq-detail-name{font-size:15px;font-weight:700;}\n' +
65
+ '.xq-detail-code{font-size:11px;color:var(--dsw-alias-label-secondary);}\n' +
66
+ '.xq-detail-cur{font-size:20px;font-weight:800;}\n' +
67
+ '.xq-detail-pct{font-size:13px;}\n' +
68
+ '.xq-stats{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;margin-bottom:8px;}\n' +
69
+ '.xq-stat{background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:6px;padding:4px 7px;}\n' +
70
+ '.xq-stat-k{font-size:10.5px;color:var(--dsw-alias-label-secondary);}\n' +
71
+ '.xq-stat-v{font-size:12.5px;font-weight:600;}\n' +
72
+ '.xq-card{background:var(--dsw-alias-bg-layer-2);border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:8px 10px;margin-bottom:8px;}\n' +
73
+ '.xq-card-t{font-size:12px;font-weight:700;margin-bottom:6px;display:flex;align-items:center;gap:8px;}\n' +
74
+ '.xq-periods{display:inline-flex;gap:2px;border:1px solid var(--dsw-alias-border-l2);border-radius:6px;padding:1px;}\n' +
75
+ '.xq-periods button,.xq-modes button{font-size:11.5px;border:none;background:none;color:var(--dsw-alias-label-secondary);padding:2px 9px;border-radius:5px;cursor:pointer;}\n' +
76
+ '.xq-periods button.xq-on,.xq-modes button.xq-on{background:var(--dsw-alias-bg-overlay);color:var(--dsw-alias-label-primary);font-weight:600;}\n' +
77
+ '.xq-chart{width:100%;height:auto;display:block;}\n' +
78
+ '.xq-chart-labels{display:flex;justify-content:space-between;font-size:10.5px;color:var(--dsw-alias-label-secondary);margin-top:2px;}\n' +
79
+ '.xq-ma-legend{display:flex;gap:10px;font-size:10.5px;color:var(--dsw-alias-label-secondary);}\n' +
80
+ '.xq-kol{display:flex;flex-wrap:wrap;gap:6px;}\n' +
81
+ '.xq-kol-chip{font-size:12px;padding:4px 10px;border-radius:14px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-1);cursor:pointer;}\n' +
82
+ '.xq-kol-chip:hover{border-color:var(--dsw-alias-brand-primary);}\n' +
83
+ '.xq-verif{font-size:9.5px;color:var(--dsw-alias-brand-primary);margin-left:4px;}\n' +
84
+ '.xq-hot-row{display:flex;align-items:center;gap:8px;padding:6px 8px;border-bottom:1px solid var(--dsw-alias-border-l1);cursor:pointer;}\n' +
85
+ '.xq-hot-row:last-child{border-bottom:none;}\n' +
86
+ '.xq-hot-row:hover{background:var(--dsw-alias-bg-layer-2);}\n' +
87
+ '.xq-rank{font-size:12px;font-weight:700;width:20px;text-align:center;color:var(--dsw-alias-label-secondary);}\n' +
88
+ '.xq-ticker{display:flex;gap:14px;font-size:11px;color:var(--dsw-alias-label-secondary);padding:2px 2px;flex-wrap:wrap;cursor:pointer;}\n' +
89
+ '.xq-ticker:hover{color:var(--dsw-alias-label-primary);}\n' +
90
+ '.xq-tick{display:inline-flex;gap:5px;align-items:baseline;}\n' +
91
+ '.xq-tick-name{color:var(--dsw-alias-label-secondary);}\n' +
92
+ '.xq-tick-cur{font-weight:600;}\n' +
93
+ '.xq-sum{font-size:11.5px;color:var(--dsw-alias-label-secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}\n' +
94
+ '.xq-caret{font-size:11px;color:var(--dsw-alias-label-secondary);flex-shrink:0;}\n' +
95
+ '.xq-loading{font-size:12px;color:var(--dsw-alias-label-secondary);padding:12px 0;text-align:center;}\n'
96
+ )
97
+
98
+ function el(type, props, children) { return React.createElement(type, props, children) }
99
+
100
+ async function call(action, args) {
101
+ const connection = ctx.get('connection')
102
+ if (!connection || !connection.rpc) throw new Error('connection 服务不可用,无法访问雪球')
103
+ const r = await connection.rpc.call('/xueqiu', 'call', { action: action, args: args || {} })
104
+ if (!r || !r.ok) throw new Error((r && r.error && r.error.message) || '调用失败')
105
+ return r.value
106
+ }
107
+
108
+ function fmt(v, d) {
109
+ if (v === null || v === undefined || v === '') return '--'
110
+ const n = Number(v)
111
+ if (!isFinite(n)) return '--'
112
+ const digits = (d === undefined) ? 2 : d
113
+ return n.toFixed(digits)
114
+ }
115
+ function fmtPct(v) {
116
+ if (v === null || v === undefined) return '--'
117
+ const n = Number(v)
118
+ if (!isFinite(n)) return '--'
119
+ return (n >= 0 ? '+' : '') + n.toFixed(2) + '%'
120
+ }
121
+ function fmtBig(v) {
122
+ if (v === null || v === undefined) return '--'
123
+ const n = Number(v)
124
+ if (!isFinite(n)) return '--'
125
+ if (Math.abs(n) >= 1e8) return (n / 1e8).toFixed(2) + '亿'
126
+ if (Math.abs(n) >= 1e4) return (n / 1e4).toFixed(2) + '万'
127
+ return String(n)
128
+ }
129
+ function fmtVol(v) {
130
+ if (v === null || v === undefined) return '--'
131
+ const n = Number(v)
132
+ if (!isFinite(n)) return '--'
133
+ if (n >= 1e8) return (n / 1e8).toFixed(2) + '亿手'
134
+ if (n >= 1e4) return (n / 1e4).toFixed(2) + '万手'
135
+ return String(n)
136
+ }
137
+ function fmtTime(ts) {
138
+ if (!ts) return ''
139
+ const d = new Date(Number(ts))
140
+ function p(n) { return n < 10 ? '0' + n : String(n) }
141
+ return p(d.getHours()) + ':' + p(d.getMinutes()) + ':' + p(d.getSeconds())
142
+ }
143
+ function fmtDay(ts) {
144
+ if (!ts) return ''
145
+ const d = new Date(Number(ts))
146
+ function p(n) { return n < 10 ? '0' + n : String(n) }
147
+ return p(d.getMonth() + 1) + '-' + p(d.getDate())
148
+ }
149
+ function colorOf(pct) {
150
+ if (pct === null || pct === undefined) return 'xq-flat'
151
+ const n = Number(pct)
152
+ if (n > 0) return 'xq-up'
153
+ if (n < 0) return 'xq-down'
154
+ return 'xq-flat'
155
+ }
156
+ function upColor(up) { return up ? 'var(--dsw-alias-state-error-primary)' : 'var(--dsw-alias-state-success-primary)' }
157
+
158
+ // 组件间事件总线(Panel / Entry / Ticker 共享)
159
+ const bus = {
160
+ fns: [],
161
+ on: function (fn) {
162
+ this.fns.push(fn)
163
+ const self = this
164
+ return function () {
165
+ const i = self.fns.indexOf(fn)
166
+ if (i !== -1) self.fns.splice(i, 1)
167
+ }
168
+ },
169
+ emit: function (ev) {
170
+ const fns = this.fns.slice()
171
+ for (let i = 0; i < fns.length; i++) {
172
+ try { fns[i](ev) } catch (e) { /* ignore */ }
173
+ }
174
+ }
175
+ }
176
+
177
+ // UI 状态防抖保存
178
+ const saveUi = ctx.debounce(function (s) {
179
+ call('ui.set', s).catch(function () { /* 忽略 */ })
180
+ }, 800)
181
+
182
+ // 拖拽用可变引用(面板实例唯一)
183
+ let dragRef = null
184
+
185
+ // ---------- K线蜡烛图(含成交量与均线) ----------
186
+ function KlineChart(props) {
187
+ const rows = props.rows || []
188
+ if (!rows.length) return el('div', { className: 'xq-muted' }, '暂无K线数据')
189
+ const W = 640, MAIN = 150, VOL = 44, PAD = 6, GAP = 4
190
+ const H = MAIN + VOL + GAP + PAD
191
+ let min = Infinity, max = -Infinity
192
+ for (let i = 0; i < rows.length; i++) {
193
+ const lo = Number(rows[i].low), hi = Number(rows[i].high)
194
+ if (lo < min) min = lo
195
+ if (hi > max) max = hi
196
+ }
197
+ if (!isFinite(min) || !isFinite(max) || min === max) { min -= 1; max += 1 }
198
+ const range = max - min
199
+ const n = rows.length
200
+ const step = (W - PAD * 2) / n
201
+ const bw = Math.max(step * 0.66, 1)
202
+ const yOf = function (v) { return PAD + (1 - (v - min) / range) * (MAIN - PAD * 2) }
203
+ const vTop = PAD + MAIN + GAP
204
+ const vBottom = H - PAD
205
+ const vH = vBottom - vTop
206
+ let vmax = 0
207
+ for (let i = 0; i < rows.length; i++) {
208
+ const v = Number(rows[i].volume) || 0
209
+ if (v > vmax) vmax = v
210
+ }
211
+ if (!vmax) vmax = 1
212
+ function maArr(nn) {
213
+ const out = []
214
+ for (let i = 0; i < rows.length; i++) {
215
+ if (i < nn - 1) { out.push(null); continue }
216
+ let s = 0
217
+ for (let j = i - nn + 1; j <= i; j++) s += Number(rows[j].close)
218
+ out.push(s / nn)
219
+ }
220
+ return out
221
+ }
222
+ function poly(arr, color) {
223
+ const pts = []
224
+ for (let i = 0; i < arr.length; i++) {
225
+ if (arr[i] === null || arr[i] === undefined) continue
226
+ const x = PAD + step * i + step / 2
227
+ const y = yOf(arr[i])
228
+ pts.push(x.toFixed(1) + ',' + y.toFixed(1))
229
+ }
230
+ if (pts.length < 2) return null
231
+ return el('polyline', { key: color, points: pts.join(' '), fill: 'none', stroke: color, strokeWidth: 1 })
232
+ }
233
+ const kids = []
234
+ for (let i = 0; i < n; i++) {
235
+ const r = rows[i]
236
+ const up = Number(r.close) >= Number(r.open)
237
+ const color = upColor(up)
238
+ const x = PAD + step * i + step / 2
239
+ const yh = yOf(Number(r.high)), yl = yOf(Number(r.low))
240
+ const yo = yOf(Number(r.open)), yc = yOf(Number(r.close))
241
+ const top = Math.min(yo, yc)
242
+ const hgt = Math.max(Math.abs(yc - yo), 1)
243
+ kids.push(el('line', { key: 'w' + i, x1: x, y1: yh, x2: x, y2: yl, stroke: color, strokeWidth: 1 }))
244
+ kids.push(el('rect', { key: 'c' + i, x: x - bw / 2, y: top, width: bw, height: hgt, fill: color }))
245
+ const vh = Math.max(vH * (Number(r.volume) || 0) / vmax, 0.5)
246
+ kids.push(el('rect', { key: 'v' + i, x: x - bw / 2, y: vBottom - vh, width: bw, height: vh, fill: color, opacity: 0.45 }))
247
+ }
248
+ const last = rows[n - 1]
249
+ return el('div', null, [
250
+ el('svg', { key: 's', className: 'xq-chart', viewBox: '0 0 ' + W + ' ' + H }, [
251
+ el('line', { key: 'base', x1: PAD, y1: vTop, x2: W - PAD, y2: vTop, stroke: 'var(--dsw-alias-border-l2)', strokeWidth: 1 }),
252
+ poly(maArr(5), '#f59e0b'),
253
+ poly(maArr(10), '#3b82f6'),
254
+ poly(maArr(20), '#a855f7'),
255
+ kids,
256
+ el('text', { key: 'hi', x: PAD, y: 10, fontSize: 9, fill: 'var(--dsw-alias-label-secondary)' }, '高 ' + fmt(max)),
257
+ el('text', { key: 'lo', x: PAD, y: MAIN - 2, fontSize: 9, fill: 'var(--dsw-alias-label-secondary)' }, '低 ' + fmt(min)),
258
+ el('text', { key: 'last', x: W - PAD, y: Math.max(yOf(Number(last.close)) - 4, 10), fontSize: 9, fill: upColor(Number(last.close) >= Number(rows[n - 2] ? rows[n - 2].close : last.open)), textAnchor: 'end' }, fmt(last.close))
259
+ ]),
260
+ el('div', { key: 'lb', className: 'xq-chart-labels' }, [
261
+ el('span', { key: 'd' }, fmtDay(rows[0].timestamp) + ' ~ ' + fmtDay(last.timestamp)),
262
+ el('span', { key: 'ma', className: 'xq-ma-legend' }, [
263
+ el('span', { key: 'm5', style: { color: '#f59e0b' } }, 'MA5'),
264
+ el('span', { key: 'm10', style: { color: '#3b82f6' } }, 'MA10'),
265
+ el('span', { key: 'm20', style: { color: '#a855f7' } }, 'MA20'),
266
+ el('span', { key: 'n' }, n + ' 根')
267
+ ])
268
+ ])
269
+ ])
270
+ }
271
+
272
+ // ---------- 分时图 ----------
273
+ function MinuteChart(props) {
274
+ const items = props.items || []
275
+ const lastClose = Number(props.lastClose)
276
+ if (!items.length) return el('div', { className: 'xq-muted' }, '暂无分时数据')
277
+ const W = 640, H = 170, PAD = 6
278
+ let min = Infinity, max = -Infinity
279
+ for (let i = 0; i < items.length; i++) {
280
+ const c = Number(items[i].current)
281
+ if (c < min) min = c
282
+ if (c > max) max = c
283
+ }
284
+ if (lastClose) { if (lastClose < min) min = lastClose; if (lastClose > max) max = lastClose }
285
+ if (!isFinite(min) || !isFinite(max) || min === max) { min -= 1; max += 1 }
286
+ const range = max - min
287
+ const yOf = function (v) { return PAD + (1 - (v - min) / range) * (H - PAD * 2) }
288
+ const xOf = function (i) { return PAD + (i / (items.length - 1)) * (W - PAD * 2) }
289
+ const pricePts = []
290
+ const avgPts = []
291
+ for (let i = 0; i < items.length; i++) {
292
+ pricePts.push(xOf(i).toFixed(1) + ',' + yOf(Number(items[i].current)).toFixed(1))
293
+ const avg = Number(items[i].avg_price) || Number(items[i].current)
294
+ avgPts.push(xOf(i).toFixed(1) + ',' + yOf(avg).toFixed(1))
295
+ }
296
+ const last = Number(items[items.length - 1].current)
297
+ const up = lastClose ? (last >= lastClose) : true
298
+ const stroke = upColor(up)
299
+ const yBase = lastClose ? yOf(lastClose) : null
300
+ const kids = [
301
+ yBase !== null ? el('line', { key: 'base', x1: PAD, y1: yBase, x2: W - PAD, y2: yBase, stroke: 'var(--dsw-alias-border-l2)', strokeWidth: 1, strokeDasharray: '3 3' }) : null,
302
+ el('polyline', { key: 'avg', points: avgPts.join(' '), fill: 'none', stroke: 'var(--dsw-alias-state-warn-primary)', strokeWidth: 1 }),
303
+ el('polyline', { key: 'p', points: pricePts.join(' '), fill: 'none', stroke: stroke, strokeWidth: 1.6 }),
304
+ el('text', { key: 'hi', x: PAD, y: 10, fontSize: 9, fill: 'var(--dsw-alias-label-secondary)' }, '高 ' + fmt(max)),
305
+ el('text', { key: 'lo', x: PAD, y: H - 4, fontSize: 9, fill: 'var(--dsw-alias-label-secondary)' }, '低 ' + fmt(min)),
306
+ el('text', { key: 'last', x: W - PAD, y: Math.max(yOf(last) - 4, 10), fontSize: 9, fill: stroke, textAnchor: 'end' }, fmt(last))
307
+ ]
308
+ return el('div', null, [
309
+ el('svg', { key: 's', className: 'xq-chart', viewBox: '0 0 ' + W + ' ' + H }, kids),
310
+ el('div', { key: 'lb', className: 'xq-chart-labels' }, [
311
+ el('span', { key: 'd' }, fmtDay(items[0].timestamp) + ' 分时'),
312
+ el('span', { key: 'n' }, items.length + ' 笔')
313
+ ])
314
+ ])
315
+ }
316
+
317
+ // ---------- 底部指数条 ----------
318
+ function Ticker() {
319
+ const [indices, setIndices] = React.useState([])
320
+ React.useEffect(function () {
321
+ let alive = true
322
+ function refresh() {
323
+ call('quote', { symbols: ['SH000001', 'SZ399001', 'SZ399006', 'SH000300'] }).then(function (data) {
324
+ if (alive) setIndices((data && data.list) || [])
325
+ }).catch(function () { /* 静默失败 */ })
326
+ }
327
+ refresh()
328
+ const stop = ctx.interval(refresh, 30000)
329
+ return function () { alive = false; if (stop) stop() }
330
+ }, [])
331
+ if (!indices.length) return null
332
+ const kids = indices.map(function (q) {
333
+ return el('span', { key: q.symbol, className: 'xq-tick' }, [
334
+ el('span', { key: 'n', className: 'xq-tick-name' }, q.name),
335
+ el('span', { key: 'c', className: 'xq-tick-cur ' + colorOf(q.percent) }, fmt(q.current)),
336
+ el('span', { key: 'p', className: colorOf(q.percent) }, fmtPct(q.percent))
337
+ ])
338
+ })
339
+ return el('div', { className: 'xq-ticker', onClick: function () { bus.emit('open') } }, kids)
340
+ }
341
+
342
+ // ---------- 输入框上方入口条 ----------
343
+ function Entry() {
344
+ const [indices, setIndices] = React.useState([])
345
+ React.useEffect(function () {
346
+ let alive = true
347
+ function refresh() {
348
+ call('quote', { symbols: ['SH000001', 'SZ399001', 'SZ399006', 'SH000300'] }).then(function (data) {
349
+ if (alive) setIndices((data && data.list) || [])
350
+ }).catch(function () { /* 静默失败 */ })
351
+ }
352
+ refresh()
353
+ const stop = ctx.interval(refresh, 60000)
354
+ return function () { alive = false; if (stop) stop() }
355
+ }, [])
356
+ const line = indices.map(function (q) {
357
+ return q.name + ' ' + fmt(q.current) + ' ' + fmtPct(q.percent)
358
+ }).join(' · ')
359
+ return el('div', { className: 'xq-entry', onClick: function () { bus.emit('open') } }, [
360
+ el('span', { key: 'logo', className: 'xq-logo' }, [el('b', { key: 'b' }, '雪球'), ' mini']),
361
+ el('span', { key: 'sum', className: 'xq-sum' }, line || '点击打开行情面板'),
362
+ el('span', { key: 'caret', className: 'xq-caret' }, '打开 ▾')
363
+ ])
364
+ }
365
+
366
+ // ---------- 悬浮主面板 ----------
367
+ function Panel() {
368
+ const [visible, setVisible] = React.useState(true)
369
+ const [minimized, setMinimized] = React.useState(false)
370
+ const [pos, setPos] = React.useState(null)
371
+ const [tab, setTab] = React.useState('market')
372
+ const [watchlist, setWatchlist] = React.useState([])
373
+ const [quotes, setQuotes] = React.useState([])
374
+ const [indices, setIndices] = React.useState([])
375
+ const [hot, setHot] = React.useState([])
376
+ const [hotMarket, setHotMarket] = React.useState('cn')
377
+ const [news, setNews] = React.useState([])
378
+ const [searchQ, setSearchQ] = React.useState('')
379
+ const [searchMode, setSearchMode] = React.useState('stock')
380
+ const [searchRes, setSearchRes] = React.useState([])
381
+ const [searching, setSearching] = React.useState(false)
382
+ const [manualCode, setManualCode] = React.useState('')
383
+ const [view, setView] = React.useState(null)
384
+ const [detail, setDetail] = React.useState(null)
385
+ const [klinePeriod, setKlinePeriod] = React.useState('day')
386
+ const [chartMode, setChartMode] = React.useState('kline')
387
+ const [marketOpen, setMarketOpen] = React.useState(true)
388
+ const [updatedAt, setUpdatedAt] = React.useState(null)
389
+ const [err, setErr] = React.useState('')
390
+ const [loading, setLoading] = React.useState(true)
391
+ const [hydrated, setHydrated] = React.useState(false)
392
+
393
+ // 恢复 UI 状态 + 监听 bus
394
+ React.useEffect(function () {
395
+ let alive = true
396
+ call('ui.get', {}).then(function (d) {
397
+ if (!alive) return
398
+ if (d && d.pos) setPos({ x: Number(d.pos.x), y: Number(d.pos.y) })
399
+ if (d && d.tab) setTab(d.tab)
400
+ setMinimized(!!(d && d.minimized))
401
+ setHydrated(true)
402
+ }).catch(function () { setHydrated(true) })
403
+ const off = bus.on(function (ev) {
404
+ if (ev === 'open') { setVisible(true); setMinimized(false) }
405
+ if (ev === 'close') setVisible(false)
406
+ })
407
+ return function () { alive = false; off() }
408
+ }, [])
409
+
410
+ // 持久化 UI 状态(hydrated 后再写,避免覆盖)
411
+ React.useEffect(function () {
412
+ if (!hydrated) return
413
+ saveUi({ tab: tab, minimized: minimized, pos: pos })
414
+ }, [tab, minimized, pos, hydrated])
415
+
416
+ function refreshMarket() {
417
+ return Promise.all([
418
+ call('watchlist.get', {}),
419
+ call('quote', { symbols: ['SH000001', 'SZ399001', 'SZ399006', 'SH000300'] })
420
+ ]).then(function (res) {
421
+ const wl = (res[0] && res[0].symbols) || []
422
+ const status = res[1] ? res[1].status : null
423
+ setMarketOpen(status === 5 || status === 6)
424
+ setWatchlist(wl)
425
+ setIndices((res[1] && res[1].list) || [])
426
+ setUpdatedAt(Date.now())
427
+ setErr('')
428
+ if (!wl.length) return
429
+ return call('quote', { symbols: wl }).then(function (data) {
430
+ setQuotes((data && data.list) || [])
431
+ })
432
+ }).catch(function (e) {
433
+ setErr(String((e && e.message) || e))
434
+ })
435
+ }
436
+
437
+ function refreshContent() {
438
+ Promise.all([
439
+ call('hot', { market: hotMarket, size: 10 }),
440
+ call('news', { count: 20 })
441
+ ]).then(function (res) {
442
+ setHot((res[0] && res[0].list) || [])
443
+ setNews((res[1] && res[1].items) || [])
444
+ setErr('')
445
+ }).catch(function (e) {
446
+ setErr(String((e && e.message) || e))
447
+ })
448
+ }
449
+
450
+ // 初始加载
451
+ React.useEffect(function () {
452
+ setLoading(true)
453
+ refreshMarket().then(function () { return refreshContent() })
454
+ .then(function () { setLoading(false) })
455
+ .catch(function () { setLoading(false) })
456
+ return function () { /* 一次性 */ }
457
+ }, [])
458
+
459
+ // 智能刷新:盘中 20s/60s,收盘 60s/180s
460
+ React.useEffect(function () {
461
+ const marketMs = marketOpen ? 20000 : 60000
462
+ const contentMs = marketOpen ? 60000 : 180000
463
+ const stopA = ctx.interval(function () { refreshMarket() }, marketMs)
464
+ const stopB = ctx.interval(function () { refreshContent() }, contentMs)
465
+ return function () { if (stopA) stopA(); if (stopB) stopB() }
466
+ }, [marketOpen])
467
+
468
+ // 个股详情
469
+ React.useEffect(function () {
470
+ if (!view) { setDetail(null); return }
471
+ let alive = true
472
+ setDetail(null)
473
+ Promise.all([
474
+ call('quoteDetail', { symbol: view }),
475
+ call('kline', { symbol: view, period: klinePeriod, count: 120 }),
476
+ call('minute', { symbol: view }),
477
+ call('finance', { symbol: view }),
478
+ call('kol', { symbol: view, count: 6 })
479
+ ]).then(function (res) {
480
+ if (!alive) return
481
+ setDetail({ quote: res[0].quote, kline: res[1], minute: res[2], finance: res[3], kol: (res[4] && res[4].list) || [] })
482
+ }).catch(function (e) {
483
+ if (alive) setErr(String((e && e.message) || e))
484
+ })
485
+ return function () { alive = false }
486
+ }, [view, klinePeriod])
487
+
488
+ function openDetail(symbol) {
489
+ setChartMode('kline')
490
+ setKlinePeriod('day')
491
+ setView(symbol)
492
+ }
493
+
494
+ function addWatch(symbol) {
495
+ call('watchlist.add', { symbol: symbol }).then(function (data) {
496
+ setWatchlist((data && data.symbols) || [])
497
+ refreshMarket()
498
+ }).catch(function (e) { setErr(String((e && e.message) || e)) })
499
+ }
500
+
501
+ function removeWatch(symbol) {
502
+ call('watchlist.remove', { symbol: symbol }).then(function (data) {
503
+ setWatchlist((data && data.symbols) || [])
504
+ setQuotes(quotes.filter(function (q) { return q.symbol !== symbol }))
505
+ }).catch(function (e) { setErr(String((e && e.message) || e)) })
506
+ }
507
+
508
+ function doSearch() {
509
+ const q = searchQ.trim()
510
+ if (!q) return
511
+ setSearching(true)
512
+ const p = searchMode === 'stock'
513
+ ? call('search', { q: q, count: 8 })
514
+ : call('searchPosts', { q: q, count: 10 })
515
+ p.then(function (data) {
516
+ setSearchRes((data && data.list) || [])
517
+ }).catch(function (e) {
518
+ setErr(String((e && e.message) || e))
519
+ setSearchRes([])
520
+ }).then(function () { setSearching(false) })
521
+ }
522
+
523
+ function addManual() {
524
+ const code = manualCode.trim().toUpperCase()
525
+ if (!code) return
526
+ addWatch(code)
527
+ setManualCode('')
528
+ }
529
+
530
+ // 拖拽
531
+ function onTitleDown(e) {
532
+ if (e.pointerType === 'mouse' && e.button !== 0) return
533
+ const baseX = pos ? pos.x : e.clientX
534
+ const baseY = pos ? pos.y : e.clientY
535
+ dragRef = { dx: e.clientX - baseX, dy: e.clientY - baseY }
536
+ try { e.currentTarget.setPointerCapture(e.pointerId) } catch (err) { /* ignore */ }
537
+ }
538
+ function onTitleMove(e) {
539
+ if (!dragRef) return
540
+ setPos({ x: Math.max(4, e.clientX - dragRef.dx), y: Math.max(4, e.clientY - dragRef.dy) })
541
+ }
542
+ function onTitleUp(e) {
543
+ dragRef = null
544
+ try {
545
+ if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId)
546
+ } catch (err) { /* ignore */ }
547
+ }
548
+
549
+ if (!visible) return null
550
+
551
+ const dragProps = {
552
+ onPointerDown: onTitleDown,
553
+ onPointerMove: onTitleMove,
554
+ onPointerUp: onTitleUp,
555
+ onPointerCancel: onTitleUp
556
+ }
557
+
558
+ // 最小化条
559
+ if (minimized) {
560
+ const idxLine = indices.map(function (q) {
561
+ return q.name + ' ' + fmt(q.current) + ' ' + fmtPct(q.percent)
562
+ }).join(' · ')
563
+ return el('div', { className: 'xq-float xq-min', style: pos ? { left: pos.x, top: pos.y, right: 'auto', bottom: 'auto' } : null, onClick: function () { setMinimized(false) }, ...dragProps }, [
564
+ el('span', { key: 'logo', className: 'xq-logo' }, [el('b', { key: 'b' }, '雪球'), ' mini']),
565
+ el('span', { key: 'sum', className: 'xq-sum' }, idxLine || '点击展开行情面板'),
566
+ el('span', { key: 'sp', className: 'xq-spacer' }),
567
+ el('button', { key: 'x', className: 'xq-btn-mini', onClick: function (e) { e.stopPropagation(); setVisible(false) }, onPointerDown: function (e) { e.stopPropagation() } }, '✕'),
568
+ el('span', { key: 'caret', className: 'xq-caret' }, '展开 ▾')
569
+ ])
570
+ }
571
+
572
+ // 标题栏
573
+ const titleBar = el('div', { className: 'xq-title', ...dragProps }, [
574
+ el('span', { key: 'logo', className: 'xq-logo' }, [el('b', { key: 'b' }, '雪球'), ' mini']),
575
+ el('span', { key: 'st', className: 'xq-status' + (marketOpen ? ' xq-live' : '') }, marketOpen ? '● 盘中' : '已收盘'),
576
+ el('span', { key: 'upd', className: 'xq-update' }, updatedAt ? ('更新 ' + fmtTime(updatedAt)) : (loading ? '加载中…' : '')),
577
+ el('span', { key: 'sp', className: 'xq-spacer' }),
578
+ el('button', { key: 'min', className: 'xq-btn-mini', title: '收起', onPointerDown: function (e) { e.stopPropagation() }, onClick: function (e) { e.stopPropagation(); setMinimized(true) } }, '—'),
579
+ el('button', { key: 'cls', className: 'xq-btn-mini', title: '关闭(可从下方入口重新打开)', onPointerDown: function (e) { e.stopPropagation() }, onClick: function (e) { e.stopPropagation(); setVisible(false) } }, '✕')
580
+ ])
581
+
582
+ const tabs = el('div', { className: 'xq-tabs' }, [
583
+ ['market', '行情'], ['hot', '热榜'], ['search', '搜索'], ['news', '快讯']
584
+ ].map(function (t) {
585
+ return el('button', {
586
+ key: t[0], className: 'xq-tab' + (tab === t[0] ? ' xq-tab-active' : ''),
587
+ onClick: function () { setTab(t[0]) }
588
+ }, t[1])
589
+ }).concat([
590
+ el('span', { key: 'sp', className: 'xq-spacer' }),
591
+ el('button', {
592
+ key: 'btn', className: 'xq-btn', disabled: loading,
593
+ onClick: function () {
594
+ setLoading(true)
595
+ Promise.all([refreshMarket(), refreshContent()]).then(function () { setLoading(false) }).catch(function () { setLoading(false) })
596
+ }
597
+ }, '刷新')
598
+ ]))
599
+
600
+ const errBox = err ? el('div', { className: 'xq-err' }, err) : null
601
+
602
+ // 行情 tab
603
+ function MarketTab() {
604
+ const idxKids = indices.map(function (q) {
605
+ return el('div', { key: q.symbol, className: 'xq-idx-card' }, [
606
+ el('div', { key: 'n', className: 'xq-idx-name' }, q.name),
607
+ el('div', { key: 'r', className: 'xq-idx-row' }, [
608
+ el('span', { key: 'c', className: 'xq-idx-cur ' + colorOf(q.percent) }, fmt(q.current)),
609
+ el('span', { key: 'p', className: 'xq-idx-pct ' + colorOf(q.percent) }, fmtPct(q.percent))
610
+ ])
611
+ ])
612
+ })
613
+ const rows = quotes.map(function (q) {
614
+ return el('div', { key: q.symbol, className: 'xq-grid-row' }, [
615
+ el('div', { key: 'n' }, [
616
+ el('div', { key: 'a', className: 'xq-name' }, q.name),
617
+ el('div', { key: 'b', className: 'xq-sub' }, q.symbol)
618
+ ]),
619
+ el('div', { key: 'c', className: colorOf(q.percent) }, fmt(q.current)),
620
+ el('div', { key: 'p', className: colorOf(q.percent) }, fmtPct(q.percent)),
621
+ el('div', { key: 'v', className: 'xq-sub' }, fmtVol(q.volume)),
622
+ el('div', { key: 'a2', className: 'xq-actions' }, [
623
+ el('button', { key: 'd', className: 'xq-btn-mini', onClick: function () { openDetail(q.symbol) } }, '详情'),
624
+ el('button', { key: 'r', className: 'xq-btn-mini', onClick: function () { removeWatch(q.symbol) } }, '×')
625
+ ])
626
+ ])
627
+ })
628
+ return el('div', null, [
629
+ el('div', { key: 'idx', className: 'xq-idx' }, idxKids),
630
+ el('div', { key: 'wl', className: 'xq-grid' }, [
631
+ el('div', { key: 'h', className: 'xq-grid-hd' }, ['名称', '现价', '涨跌幅', '成交量', '操作'].map(function (t, i) {
632
+ return el('span', { key: i }, t)
633
+ })),
634
+ rows.length ? rows : el('div', { key: 'empty', className: 'xq-grid-row' }, el('span', { key: 'e', className: 'xq-muted' }, '自选股为空,去「搜索」或下方添加'))
635
+ ]),
636
+ el('div', { key: 'add', className: 'xq-search-row' }, [
637
+ el('input', {
638
+ key: 'i', className: 'xq-input', placeholder: '添加代码,如 SH600519 / 00700 / AAPL',
639
+ value: manualCode,
640
+ onChange: function (e) { setManualCode(e.target.value) },
641
+ onKeyDown: function (e) { if (e.key === 'Enter') addManual() }
642
+ }),
643
+ el('button', { key: 'b', className: 'xq-btn', onClick: addManual }, '添加')
644
+ ])
645
+ ])
646
+ }
647
+
648
+ // 个股详情
649
+ function DetailView() {
650
+ if (!detail) return el('div', { className: 'xq-loading' }, '加载中…')
651
+ const q = detail.quote || {}
652
+ const kl = detail.kline || { rows: [] }
653
+ const mn = detail.minute || { items: [], last_close: null }
654
+ const fin = detail.finance || { list: [] }
655
+ const kol = detail.kol || []
656
+ const firstFin = fin.list && fin.list.length ? fin.list[0] : null
657
+ const stats = [
658
+ ['今开', fmt(q.open)], ['昨收', fmt(q.last_close)], ['最高', fmt(q.high)], ['最低', fmt(q.low)],
659
+ ['成交量', fmtVol(q.volume)], ['成交额', fmtBig(q.amount)], ['换手率', fmt(q.turnover_rate) + '%'], ['振幅', fmt(q.amplitude) + '%'],
660
+ ['总市值', fmtBig(q.market_capital)], ['流通市值', fmtBig(q.float_market_capital)], ['量比', fmt(q.volume_ratio)], ['PE(TTM)', fmt(q.pe_ttm)],
661
+ ['PB', fmt(q.pb)], ['股息率', fmt(q.dividend_yield) + '%'], ['52周高', fmt(q.high52w)], ['52周低', fmt(q.low52w)]
662
+ ]
663
+ const finStats = firstFin ? [
664
+ ['ROE', fmt(firstFin.avg_roe) + '%'], ['EPS', fmt(firstFin.basic_eps)],
665
+ ['毛利率', fmt(firstFin.gross_selling_rate) + '%'], ['净利率', fmt(firstFin.net_selling_rate) + '%'],
666
+ ['营收同比', fmt(firstFin.operating_income_yoy) + '%'], ['净利同比', fmt(firstFin.net_profit_atsopc_yoy) + '%'],
667
+ ['资产负债率', fmt(firstFin.asset_liab_ratio) + '%'], ['每股现金流', fmt(firstFin.operate_cash_flow_ps)]
668
+ ] : []
669
+ const kolKids = kol.map(function (u) {
670
+ return el('span', { key: u.id, className: 'xq-kol-chip' }, [
671
+ u.screen_name || ('用户' + u.id),
672
+ u.verified ? el('span', { key: 'v', className: 'xq-verif' }, '✓') : null,
673
+ ' · ' + fmtBig(u.followers_count) + '粉'
674
+ ])
675
+ })
676
+ return el('div', null, [
677
+ el('div', { key: 'h', className: 'xq-detail-head' }, [
678
+ el('button', { key: 'b', className: 'xq-btn-mini', onClick: function () { setView(null) } }, '← 返回'),
679
+ el('span', { key: 'n', className: 'xq-detail-name' }, q.name || view),
680
+ el('span', { key: 'c', className: 'xq-detail-code' }, view),
681
+ el('span', { key: 'sp', className: 'xq-spacer' }),
682
+ el('span', { key: 'cur', className: 'xq-detail-cur ' + colorOf(q.percent) }, fmt(q.current)),
683
+ el('span', { key: 'pct', className: 'xq-detail-pct ' + colorOf(q.percent) }, fmtPct(q.percent))
684
+ ]),
685
+ el('div', { key: 'st', className: 'xq-stats' }, stats.map(function (s, i) {
686
+ return el('div', { key: i, className: 'xq-stat' }, [
687
+ el('div', { key: 'k', className: 'xq-stat-k' }, s[0]),
688
+ el('div', { key: 'v', className: 'xq-stat-v' }, s[1])
689
+ ])
690
+ })),
691
+ el('div', { key: 'kl', className: 'xq-card' }, [
692
+ el('div', { key: 't', className: 'xq-card-t' }, [
693
+ el('span', { key: 't' }, '走势'),
694
+ el('span', { key: 'modes', className: 'xq-modes' }, [
695
+ el('button', { key: 'k', className: chartMode === 'kline' ? 'xq-on' : '', onClick: function () { setChartMode('kline') } }, 'K线'),
696
+ el('button', { key: 'm', className: chartMode === 'minute' ? 'xq-on' : '', onClick: function () { setChartMode('minute') } }, '分时')
697
+ ]),
698
+ el('span', { key: 'sp', className: 'xq-spacer' }),
699
+ chartMode === 'kline' ? el('span', { key: 'pd', className: 'xq-periods' }, ['day', 'week', 'month', '60m'].map(function (p) {
700
+ return el('button', {
701
+ key: p, className: klinePeriod === p ? 'xq-on' : '',
702
+ onClick: function () { setKlinePeriod(p) }
703
+ }, p === 'day' ? '日K' : p === 'week' ? '周K' : p === 'month' ? '月K' : '60分')
704
+ })) : null
705
+ ]),
706
+ chartMode === 'kline'
707
+ ? el(KlineChart, { key: 'c', rows: kl.rows })
708
+ : el(MinuteChart, { key: 'c', items: mn.items, lastClose: mn.last_close })
709
+ ]),
710
+ firstFin ? el('div', { key: 'fin', className: 'xq-card' }, [
711
+ el('div', { key: 't', className: 'xq-card-t' }, '财务指标 · ' + (firstFin.report_name || '')),
712
+ el('div', { key: 'g', className: 'xq-stats' }, finStats.map(function (s, i) {
713
+ return el('div', { key: i, className: 'xq-stat' }, [
714
+ el('div', { key: 'k', className: 'xq-stat-k' }, s[0]),
715
+ el('div', { key: 'v', className: 'xq-stat-v' }, s[1])
716
+ ])
717
+ }))
718
+ ]) : null,
719
+ kolKids.length ? el('div', { key: 'kol', className: 'xq-card' }, [
720
+ el('div', { key: 't', className: 'xq-card-t' }, '热议用户'),
721
+ el('div', { key: 'l', className: 'xq-kol' }, kolKids)
722
+ ]) : null
723
+ ])
724
+ }
725
+
726
+ // 热榜 tab
727
+ function HotTab() {
728
+ const markets = [['cn', 'A股'], ['us', '美股'], ['hk', '港股'], ['global', '全球']]
729
+ return el('div', null, [
730
+ el('div', { key: 'seg', className: 'xq-seg', style: { marginBottom: 8 } }, markets.map(function (m) {
731
+ return el('button', {
732
+ key: m[0], className: hotMarket === m[0] ? 'xq-seg-on' : '',
733
+ onClick: function () {
734
+ setHotMarket(m[0])
735
+ call('hot', { market: m[0], size: 10 }).then(function (data) {
736
+ setHot((data && data.list) || [])
737
+ }).catch(function (e) { setErr(String((e && e.message) || e)) })
738
+ }
739
+ }, m[1])
740
+ })),
741
+ el('div', { key: 'list', className: 'xq-grid' }, hot.map(function (it, i) {
742
+ return el('div', { key: it.symbol, className: 'xq-hot-row' }, [
743
+ el('span', { key: 'r', className: 'xq-rank' }, String(i + 1)),
744
+ el('div', { key: 'n' }, [
745
+ el('div', { key: 'a', className: 'xq-name' }, it.name),
746
+ el('div', { key: 'b', className: 'xq-sub' }, it.symbol)
747
+ ]),
748
+ el('span', { key: 'sp', className: 'xq-spacer' }),
749
+ el('span', { key: 'c', className: colorOf(it.percent) }, fmt(it.current)),
750
+ el('span', { key: 'p', className: colorOf(it.percent) }, fmtPct(it.percent)),
751
+ el('button', { key: 'd', className: 'xq-btn-mini', onClick: function () { openDetail(it.symbol) } }, '详情')
752
+ ])
753
+ }))
754
+ ])
755
+ }
756
+
757
+ // 搜索 tab
758
+ function SearchTab() {
759
+ const isPost = searchMode === 'post'
760
+ const resKids = searchRes.map(function (r) {
761
+ const title = isPost ? (r.title || '') : r.name
762
+ const sub = isPost ? ((r.user ? r.user.screen_name + ' · ' : '') + fmtBig(r.view_count) + '阅读') : (r.code || '')
763
+ const desc = isPost ? String(r.text || '').slice(0, 60) : sub
764
+ return el('div', { key: String(r.id || r.code), className: 'xq-grid-row' }, [
765
+ el('div', { key: 'n' }, [
766
+ el('div', { key: 'a', className: 'xq-name' }, title || '(无标题)'),
767
+ el('div', { key: 'b', className: 'xq-sub' }, desc)
768
+ ]),
769
+ el('div', { key: 'c', className: 'xq-sub' }, sub),
770
+ el('div', { key: 'p', className: 'xq-sub' }, isPost ? fmtDay(r.created_at) : ''),
771
+ el('div', { key: 'a2', className: 'xq-actions' }, isPost
772
+ ? null
773
+ : [
774
+ el('button', { key: 'd', className: 'xq-btn-mini', onClick: function () { openDetail(r.code) } }, '详情'),
775
+ el('button', { key: 'w', className: 'xq-btn-mini', onClick: function () { addWatch(r.code) } }, '加自选')
776
+ ])
777
+ ])
778
+ })
779
+ return el('div', null, [
780
+ el('div', { key: 'row', className: 'xq-search-row' }, [
781
+ el('input', {
782
+ key: 'i', className: 'xq-input', placeholder: searchMode === 'stock' ? '搜索股票,如「茅台」' : '搜索帖子,如「段永平」',
783
+ value: searchQ,
784
+ onChange: function (e) { setSearchQ(e.target.value) },
785
+ onKeyDown: function (e) { if (e.key === 'Enter') doSearch() }
786
+ }),
787
+ el('button', { key: 'b', className: 'xq-btn', disabled: searching, onClick: doSearch }, searching ? '搜索中…' : '搜索')
788
+ ]),
789
+ el('div', { key: 'seg', className: 'xq-seg', style: { marginBottom: 8 } }, [
790
+ el('button', { key: 's', className: searchMode === 'stock' ? 'xq-seg-on' : '', onClick: function () { setSearchMode('stock'); setSearchRes([]) } }, '股票'),
791
+ el('button', { key: 'p', className: searchMode === 'post' ? 'xq-seg-on' : '', onClick: function () { setSearchMode('post'); setSearchRes([]) } }, '帖子')
792
+ ]),
793
+ searchRes.length ? el('div', { key: 'res', className: 'xq-grid' }, [
794
+ el('div', { key: 'h', className: 'xq-grid-hd' }, ['结果', '', '', ''].map(function (t, i) { return el('span', { key: i }, t) })),
795
+ resKids
796
+ ]) : el('div', { key: 'tip', className: 'xq-muted' }, '输入关键词搜索,回车或点搜索')
797
+ ])
798
+ }
799
+
800
+ // 快讯 tab
801
+ function NewsTab() {
802
+ const kids = news.map(function (it) {
803
+ return el('div', { key: String(it.id), className: 'xq-news-item' + (it.mark === 1 ? ' xq-important' : '') }, [
804
+ el('div', { key: 't' }, it.text),
805
+ el('div', { key: 'm', className: 'xq-news-time' }, fmtTime(it.created_at) + (it.mark === 1 ? ' · 重要' : ''))
806
+ ])
807
+ })
808
+ return news.length
809
+ ? el('div', { className: 'xq-news' }, kids)
810
+ : el('div', { className: 'xq-muted' }, '暂无快讯')
811
+ }
812
+
813
+ let content
814
+ if (view) {
815
+ content = DetailView()
816
+ } else if (tab === 'market') {
817
+ content = MarketTab()
818
+ } else if (tab === 'hot') {
819
+ content = HotTab()
820
+ } else if (tab === 'search') {
821
+ content = SearchTab()
822
+ } else {
823
+ content = NewsTab()
824
+ }
825
+
826
+ return el('div', { className: 'xq-float', style: pos ? { left: pos.x, top: pos.y, right: 'auto', bottom: 'auto' } : null }, [
827
+ titleBar,
828
+ el('div', { key: 'body', className: 'xq-body' }, [tabs, errBox, content])
829
+ ])
830
+ }
831
+
832
+ // ---------- 注册 ----------
833
+ const slots = ctx.get('slots')
834
+ if (slots === undefined) return
835
+ slots.inject('shell.overlay', function () {
836
+ return slots.register(
837
+ { name: 'shell.overlay', id: 'xueqiu-panel' },
838
+ function () { return el(Panel, null) }
839
+ )
840
+ })
841
+ slots.inject('conversation.input.dock', function () {
842
+ return slots.register(
843
+ { name: 'conversation.input.dock', id: 'xueqiu-panel-entry', order: 30 },
844
+ function () { return el(Entry, null) }
845
+ )
846
+ })
847
+ slots.inject('conversation.composer.dock', function () {
848
+ return slots.register(
849
+ { name: 'conversation.composer.dock', id: 'xueqiu-ticker', order: 1 },
850
+ function () { return el(Ticker, null) }
851
+ )
852
+ })
853
+ }
854
+ }