Skip to content

Commit 15120c9

Browse files
author
spark
committed
feat(frontend): 优化股票代码输入和搜索功能
- 改进股票列表显示格式,增加连字符分隔 - 添加支持直接输入股票代码进行搜索的功能 - 优化股票选择逻辑,支持不同格式的股票代码 -增加调试日志输出,便于问题排查
1 parent f9a0c8d commit 15120c9

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

backend/data/stock_data_api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ func (receiver StockDataApi) GetStockCodeRealTimeData(StockCode string) (*StockI
233233
}
234234

235235
func (receiver StockDataApi) Follow(stockCode string) string {
236+
logger.SugaredLogger.Infof("Follow %s", stockCode)
236237
stockInfo, err := receiver.GetStockCodeRealTimeData(stockCode)
237238
if err != nil {
238239
logger.SugaredLogger.Error(err.Error())

frontend/src/components/stock.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ onMounted(() => {
6464
ticker.value=setInterval(() => {
6565
if(isTradingTime()){
6666
monitor()
67+
data.fenshiURL='http://image.sinajs.cn/newchart/min/n/'+data.code+'.gif'+"?t="+Date.now()
6768
}
6869
}, 3000)
6970
@@ -138,15 +139,19 @@ function removeMonitor(code,name) {
138139
})
139140
}
140141
141-
function getStockList(){
142+
function getStockList(value){
143+
console.log("getStockList",value)
142144
let result;
143145
result=stockList.value.filter(item => item.name.includes(data.name)||item.ts_code.includes(data.name))
144146
options.value=result.map(item => {
145147
return {
146-
label: item.name+" "+item.ts_code,
148+
label: item.name+" - "+item.ts_code,
147149
value: item.ts_code
148150
}
149151
})
152+
if(value.indexOf("-")<=0){
153+
data.code=value
154+
}
150155
}
151156
152157
async function monitor() {
@@ -189,7 +194,15 @@ async function monitor() {
189194
}
190195
}
191196
function onSelect(item) {
192-
data.code=item.split(".")[1].toLowerCase()+item.split(".")[0]
197+
console.log("onSelect",item)
198+
199+
if(item.indexOf("-")>0){
200+
item=item.split("-")[1].toLowerCase()
201+
}
202+
if(item.indexOf(".")>0){
203+
data.code=item.split(".")[1].toLowerCase()+item.split(".")[0]
204+
}
205+
193206
}
194207
195208
function search(code,name){
@@ -306,7 +319,7 @@ function fullscreen(){
306319
}"
307320
:options="options"
308321
placeholder="请输入股票名称或者代码"
309-
clearable @input="getStockList" :on-select="onSelect"/>
322+
clearable @update-value="getStockList" :on-select="onSelect"/>
310323
<n-button type="primary" @click="AddStock">
311324
<n-icon :component="Add"/> &nbsp;关注该股票
312325
</n-button>

0 commit comments

Comments
 (0)