mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
refactor(stock): 优化股票组件和数据更新逻辑
- 修改股票列表显示格式,将代码和名称之间的连接符改为短横线- 调整股票数据更新频率,从 3 秒改为 1 秒 - 修复当前价格为零时的显示问题,使用卖一报价替代 - 优化数据库更新操作,添加 ts_code 条件以确保更新正确性
This commit is contained in:
parent
f35847823b
commit
afe5474264
@ -203,7 +203,7 @@ func (receiver StockDataApi) GetIndexBasic() {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
db.Dao.Model(&IndexBasic{}).FirstOrCreate(index, &IndexBasic{TsCode: index.TsCode}).Updates(index)
|
||||
db.Dao.Model(&IndexBasic{}).FirstOrCreate(index, &IndexBasic{TsCode: index.TsCode}).Where("ts_code = ?", index.TsCode).Updates(index)
|
||||
}
|
||||
|
||||
}
|
||||
@ -251,7 +251,7 @@ func (receiver StockDataApi) GetStockBaseInfo() {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
db.Dao.Model(&StockBasic{}).FirstOrCreate(stock, &StockBasic{TsCode: stock.TsCode}).Updates(stock)
|
||||
db.Dao.Model(&StockBasic{}).FirstOrCreate(stock, &StockBasic{TsCode: stock.TsCode}).Where("ts_code = ?", stock.TsCode).Updates(stock)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ onBeforeMount(()=>{
|
||||
stockList.value = result
|
||||
options.value=result.map(item => {
|
||||
return {
|
||||
label: item.name+" "+item.ts_code,
|
||||
label: item.name+" - "+item.ts_code,
|
||||
value: item.ts_code
|
||||
}
|
||||
})
|
||||
@ -66,7 +66,7 @@ onMounted(() => {
|
||||
monitor()
|
||||
data.fenshiURL='http://image.sinajs.cn/newchart/min/n/'+data.code+'.gif'+"?t="+Date.now()
|
||||
}
|
||||
}, 3000)
|
||||
}, 1000)
|
||||
|
||||
})
|
||||
|
||||
@ -158,6 +158,10 @@ async function monitor() {
|
||||
for (let code of stocks.value) {
|
||||
// console.log(code)
|
||||
Greet(code).then(result => {
|
||||
if(result["当前价格"]<=0){
|
||||
result["当前价格"]=result["卖一报价"]
|
||||
}
|
||||
|
||||
let s=(result["当前价格"]-result["昨日收盘价"])*100/result["昨日收盘价"]
|
||||
let roundedNum = s.toFixed(2); // 将数字转换为保留两位小数的字符串形式
|
||||
result.s=roundedNum+"%"
|
||||
|
Loading…
x
Reference in New Issue
Block a user