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