个股搜索添加

This commit is contained in:
renzhijun
2026-02-04 11:07:11 +08:00
parent 0a2dab4936
commit 16ba613a82
3 changed files with 269 additions and 37 deletions

View File

@@ -5,9 +5,15 @@
<view class="searchC fixed flex" :style="'top:'+navH+'px;'">
<image class="icon" src="/static/icon/home/conceptCenter/search.png" mode="widthFix"></image>
<input class="flex1" type="text" v-model="keywords" placeholder="输入股票代码或名称"
placeholder-style="color:#eeeeee" confirm-type="search" @confirm="clickSearch()" />
placeholder-style="color:#eeeeee" confirm-type="search" @input="clickSearch()" />
</view>
<view v-if="searchShow" class="searchResultList fixed" :style="'top:'+searchResultTop+'px;'" @click="clickSearchResultBg()">
<view class="list">
<view class="item" v-for="(item,index) in searchResultList" :key="index" @click.stop="clickSearchResultListItem(item)">
{{item.stock_code}} {{item.stock_name}}
</view>
</view>
</view>
<scroll-view scroll-y class="stockDetailsC fixed" :style="'top:'+contentTop+'px;'">
<view>
<view style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 16rpx; padding: 20rpx;">
@@ -74,12 +80,12 @@
mode="widthFix"></image>
<view style="font-size: 28rpx; color: #2B2B2B; font-weight: bold; flex: 1; margin-left: 10rpx;">异动监控
</view>
<view @click="allAction(1)"
<!-- <view @click="allAction(1)"
style="border: 1rpx solid #DCDCDC; border-radius: 5rpx; padding: 2rpx 10rpx; display: flex; align-items: center; justify-content: center; margin: 0 10rpx;">
<view style="color: #888888; font-size: 22rpx; font-weight: 500;">全部</view>
<image style="width: 11rpx; height: 6rpx; margin-left: 40rpx;"
src="/static/icon/invest/downArrow.png" mode="widthFix"></image>
</view>
</view> -->
<view @click="allAction(2)"
style="border: 1rpx solid #DCDCDC; border-radius: 5rpx; padding: 2rpx 10rpx; display: flex; align-items: center; justify-content: center;">
<view style="color: #888888; font-size: 22rpx; font-weight: 500;">{{currentDate}}</view>
@@ -88,9 +94,9 @@
</view>
</view>
<view
<!-- <view
style="height: 400rpx; display: flex; align-items: center; justify-content: center; background-color: red;">
折线图占位 </view>
折线图占位 </view> -->
<view style="height: 1rpx; margin: 0 20rpx; background-color: #E7E7E7;"></view>
<view style="height: 88rpx; display: flex; align-items: center; margin: 0 20rpx;">
@@ -107,8 +113,9 @@
<view style="display: flex; align-items: center; margin-top: 10rpx;">
<view style="color: #2B2B2B; font-weight: bold; font-size: 26rpx; margin-right: 10rpx;">
{{item.concept_name}}
{{truncateText(item.concept_name, 5)}}
</view>
<view :style="{
color: alertTypeConfig[item.alert_type]?.color || '#FF7A45',
fontSize: '20rpx',
@@ -306,8 +313,11 @@
marketHeatmap,
marketStatistics,
marketHotspotOverview,
conceptStocks
conceptStocks,
searchStockInfo,
stockBasicInfo
} from '@/request/api'
export default {
data() {
return {
@@ -431,26 +441,116 @@
formattedAvg: 0,
upCount: 0,
downCount: 0,
limit_up_ratio: 0
limit_up_ratio: 0,
searchResultTop:'', //搜索结果
contentTop: '',
keywords: '', //搜索关键字
searchShow:false, //是否展示搜索结果
searchResultList:[], //搜索结果
selectSearchStockInfo:null, //选中的搜索股票信息
isShowTime:false
}
},
onLoad(e) {
this.activeIndex = e.index
this.contentTop = this.navH + (20 + 70 + 25) / 750 * inject('windowWidth')
//this.conceptsDailyTop()
const now = new Date()
const year = now.getFullYear()
const month = (now.getMonth() + 1).toString().padStart(2, '0')
const day = now.getDate().toString().padStart(2, '0')
this.currentDate = `${year}-${month}-${day}`
this.activeIndex = e.index
this.searchResultTop = this.navH + (20 + 70) / 750 * inject('windowWidth')
this.contentTop = this.navH + (20 + 70 + 25) / 750 * inject('windowWidth')
this.conceptsDailyTop()
// 获取当前日期,并减去一天
const now = new Date()
// 核心修改:将日期减去 1 天1 天 = 24 * 60 * 60 * 1000 毫秒)
now.setTime(now.getTime() - 24 * 60 * 60 * 1000)
const year = now.getFullYear()
const month = (now.getMonth() + 1).toString().padStart(2, '0')
const day = now.getDate().toString().padStart(2, '0')
this.currentDate = `${year}-${month}-${day}`
},
onShow() {
this.isShowTime=false;
this.marketHeatmap();
this.marketStatistics()
this.marketHotspotListOverview()
},
methods: {
truncateText(text, length) {
if (!text) return ''; // 处理空值,避免报错
return text.length > length
? text.substring(0, length) + '...'
: text;
},
/**
* 点击搜索
*/
clickSearch() {
if(this.keywords) {
this.getSearchStockInfoListData()
}else
this.selectSearchStockInfo = null
},
/**
* 点击搜索结果背景
*/
clickSearchResultBg()
{
this.searchShow = false
},
/**
* 点击搜索结果列表项
*/
clickSearchResultListItem(item) {
this.selectSearchStockInfo = item
this.searchShow = false
this.getStockBasicInfoData()
//this.getQuoteDetailsData()
},
/**
* 根据输入内容获取搜索列表项
*/
getSearchStockInfoListData() {
let param = {q:this.keywords,limit:10}
searchStockInfo(param).then(res=>{
this.searchResultList = res.data
this.searchShow = this.searchResultList.length>0
}).catch(error=>{
})
},
/**
* 获取股票基本信息
*/
getStockBasicInfoData() {
let code = this.stockCode
if (this.selectSearchStockInfo) {
code = this.selectSearchStockInfo.stock_code
}
// stockBasicInfo(code).then(res=>{
// this.stockBasicInfo = res.data
// this.navTitle = res.data.SECNAME+'('+res.data.SECCODE+')'
// }).catch(error=>{
// })
uni.navigateTo({
url: '/pagesStock/stockCenterDetails/stockCenterDetails?code=' + code
})
},
/**
* 获取股票当前市场价格信息
*/
getQuoteDetailsData() {
let code = this.stockCode
if (this.selectSearchStockInfo) {
code = this.selectSearchStockInfo.stock_code
}
quoteDetailsInfo(code).then(res=>{
this.quoteDetailsInfo = res.data
}).catch(error=>{
})
},
formatAlpha(value) {
// 1. 空值/非数字处理
if (value === null || value === undefined || isNaN(Number(value))) {
@@ -519,9 +619,13 @@
let param = {
limit: 500
}
if (currentDate && currentDate !== 'undefined' && currentDate.trim() !== '') {
param.date = currentDate;
if(this.isShowTime){
if (currentDate && currentDate !== 'undefined' && currentDate.trim() !== '') {
param.date = currentDate;
}
}
marketHeatmap(param).then(res => {
this.topLists[2].value = res.statistics.rising_count + "/" + res.statistics.falling_count;
// 存储原始数据
@@ -694,9 +798,14 @@
})
},
moreAction() {
if(this.isShowTime){
uni.navigateTo({
url: '/pages/geGuCenter/detail?currentDate=' + this.currentDate
})
})}else{
uni.navigateTo({
url: '/pages/geGuCenter/detail'
})
}
},
allAction(index) {
if (index == 1) {
@@ -734,6 +843,7 @@
const day = now.getDate().toString().padStart(2, '0')
this.currentDate = `${year}-${month}-${day}`
}
this.isShowTime=true;
this.marketHeatmap(this.currentDate)
this.marketStatistics()
@@ -846,4 +956,26 @@
border-radius: 20rpx 20rpx 0 0;
padding-bottom: env(safe-area-inset-bottom);
}
.searchResultList {
background-color: #00000080;
left: 0;
right: 0;
bottom: 0;
padding: 0 25rpx;
.list
{
background-color: white;
border-radius: 10rpx;
.item
{
padding: 0 42rpx;
line-height: 60rpx;
font-size: 22rpx;
font-weight: 500;
color: #333;
}
}
z-index: 20;
}
</style>