涨停分析,异常数据对接,词云优化
This commit is contained in:
@@ -188,48 +188,40 @@
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
// 筛选后的股票列表
|
||||
filteredStocks() {
|
||||
if (!this.allStocks.length) return [];
|
||||
|
||||
let stocks = [...this.allStocks];
|
||||
|
||||
// 先筛选当前选中板块的股票
|
||||
if (this.activeIndex >= 0 && this.bkList.length) {
|
||||
const currentSector = this.bkList[this.activeIndex]?.title;
|
||||
if (currentSector) {
|
||||
stocks = stocks.filter(stock => {
|
||||
// 匹配核心板块或板块分类
|
||||
const sectorMatch = stock.core_sectors.some(s => s.includes(currentSector)) ||
|
||||
(Array.isArray(stock.sector_category) ? stock.sector_category.includes(currentSector) : stock.sector_category === currentSector);
|
||||
return sectorMatch;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 根据筛选类型排序/过滤
|
||||
switch (this.filterIndex) {
|
||||
case 0: // 按连板数
|
||||
stocks.sort((a, b) => {
|
||||
const aDays = this.parseContinuousDays(a.continuous_days);
|
||||
const bDays = this.parseContinuousDays(b.continuous_days);
|
||||
return bDays - aDays;
|
||||
});
|
||||
break;
|
||||
case 1: // 只看龙头(≥2连板)
|
||||
stocks = stocks.filter(stock => this.parseContinuousDays(stock.continuous_days) >= 2);
|
||||
stocks.sort((a, b) => {
|
||||
const aDays = this.parseContinuousDays(a.continuous_days);
|
||||
const bDays = this.parseContinuousDays(b.continuous_days);
|
||||
return bDays - aDays;
|
||||
});
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return stocks;
|
||||
}
|
||||
},
|
||||
// 筛选后的股票列表:按板块codes匹配 + 连板排序/筛选
|
||||
filteredStocks() {
|
||||
if (!this.originData?.stocks || !this.bkList.length) return [];
|
||||
|
||||
// 1. 获取当前选中板块的股票代码集合
|
||||
const currentBk = this.bkList[this.activeIndex];
|
||||
if (!currentBk?.codes || currentBk.codes.length === 0) return [];
|
||||
const targetCodes = new Set(currentBk.codes); // 转Set提升匹配效率
|
||||
|
||||
// 2. 从stocks中筛选出scode在targetCodes中的股票
|
||||
let stocks = this.originData.stocks.filter(stock => targetCodes.has(stock.scode));
|
||||
|
||||
// 3. 保留原有筛选/排序逻辑
|
||||
switch (this.filterIndex) {
|
||||
case 0: // 按连板数从高到低排序
|
||||
stocks.sort((a, b) => {
|
||||
const aDays = this.parseContinuousDays(a.continuous_days);
|
||||
const bDays = this.parseContinuousDays(b.continuous_days);
|
||||
return bDays - aDays;
|
||||
});
|
||||
break;
|
||||
case 1: // 只看龙头(≥2连板),并按连板数从高到低排序
|
||||
stocks = stocks.filter(stock => this.parseContinuousDays(stock.continuous_days) >= 2);
|
||||
stocks.sort((a, b) => {
|
||||
const aDays = this.parseContinuousDays(a.continuous_days);
|
||||
const bDays = this.parseContinuousDays(b.continuous_days);
|
||||
return bDays - aDays;
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
return stocks;
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(e) {
|
||||
this.activeIndex = e.index
|
||||
@@ -351,99 +343,85 @@ computed: {
|
||||
},
|
||||
|
||||
|
||||
// 为所有股票添加角色标签
|
||||
setStockRoles() {
|
||||
if (!this.originData || !this.originData.stocks || !this.bkList.length) return;
|
||||
console.log("setStockRoles",JSON.stringify(this.originData.stocks))
|
||||
this.allStocks = this.originData.stocks.map(stock => {
|
||||
// 找到股票所属板块的热度排名
|
||||
let sectorIndex = -1;
|
||||
const stockSectors = Array.isArray(stock.sector_category) ? stock.sector_category : [stock.sector_category];
|
||||
|
||||
// 匹配板块列表中的位置
|
||||
this.bkList.some((bk, idx) => {
|
||||
const match = stockSectors.some(s => s.includes(bk.title));
|
||||
if (match) {
|
||||
sectorIndex = idx;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// 获取同板块的所有股票
|
||||
const sectorStocks = this.originData.stocks.filter(s => {
|
||||
const sSectors = Array.isArray(s.sector_category) ? s.sector_category : [s.sector_category];
|
||||
return sSectors.some(ss => stockSectors.includes(ss));
|
||||
});
|
||||
|
||||
// 获取股票角色
|
||||
const stockRole = this.getStockRole(stock, sectorStocks, sectorIndex);
|
||||
|
||||
return {
|
||||
...stock,
|
||||
stockRole: stockRole.text ? stockRole : null
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
// 为所有股票添加角色标签
|
||||
setStockRoles() {
|
||||
if (!this.originData || !this.originData.stocks || !this.bkList.length) return;
|
||||
this.allStocks = this.originData.stocks.map(stock => {
|
||||
// 找到股票所属板块的热度排名
|
||||
let sectorIndex = -1;
|
||||
const stockSectors = Array.isArray(stock.sector_category) ? stock.sector_category : [stock.sector_category];
|
||||
// 匹配板块列表中的位置
|
||||
this.bkList.some((bk, idx) => {
|
||||
const match = stockSectors.some(s => s.includes(bk.title));
|
||||
if (match) {
|
||||
sectorIndex = idx;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// 获取同板块的所有股票
|
||||
const sectorStocks = this.originData.stocks.filter(s => {
|
||||
const sSectors = Array.isArray(s.sector_category) ? s.sector_category : [s.sector_category];
|
||||
return sSectors.some(ss => stockSectors.includes(ss));
|
||||
});
|
||||
// 获取股票角色
|
||||
const stockRole = this.getStockRole(stock, sectorStocks, sectorIndex);
|
||||
return {
|
||||
...stock,
|
||||
stockRole: stockRole.text ? stockRole : null
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 请求接口数据(优化:动态日期+自动时间戳)
|
||||
*/
|
||||
// 请求接口数据
|
||||
async fetchData() {
|
||||
try {
|
||||
const timestamp = new Date().getTime();
|
||||
const formattedDate = this.selectedFullDate;
|
||||
const baseURL = getBaseURL1();
|
||||
const requestUrl = `${baseURL}/data/zt/daily/${formattedDate}.json?t=${timestamp}`;
|
||||
|
||||
console.log('请求URL:', requestUrl);
|
||||
|
||||
const res = await uni.request({
|
||||
url: requestUrl,
|
||||
method: 'GET'
|
||||
});
|
||||
|
||||
if (res.statusCode === 200 && res.data) {
|
||||
this.originData = res.data;
|
||||
|
||||
// 处理板块列表
|
||||
const chartData = this.originData.chart_data || {};
|
||||
const labels = chartData.labels || [];
|
||||
const counts = chartData.counts || [];
|
||||
|
||||
const maxCount = counts.length > 0 ? Math.max(...counts) : 0;
|
||||
const maxLen = Math.min(labels.length, counts.length);
|
||||
let bkList = [];
|
||||
|
||||
for (let i = 0; i < maxLen; i++) {
|
||||
const title = labels[i];
|
||||
const count = counts[i] || 0;
|
||||
bkList.push({
|
||||
title,
|
||||
count
|
||||
});
|
||||
}
|
||||
|
||||
this.bkList = bkList;
|
||||
|
||||
// 为股票添加角色标签
|
||||
this.setStockRoles();
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '数据请求失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('请求异常:', error);
|
||||
uni.showToast({
|
||||
title: '网络异常',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
async fetchData() {
|
||||
try {
|
||||
const timestamp = new Date().getTime();
|
||||
const formattedDate = this.selectedFullDate;
|
||||
const baseURL = getBaseURL1();
|
||||
const requestUrl = `${baseURL}/data/zt/daily/${formattedDate}.json?t=${timestamp}`;
|
||||
|
||||
console.log('请求URL:', requestUrl);
|
||||
const res = await uni.request({
|
||||
url: requestUrl,
|
||||
method: 'GET'
|
||||
});
|
||||
|
||||
if (res.statusCode === 200 && res.data) {
|
||||
this.originData = res.data;
|
||||
const { sector_data } = this.originData;
|
||||
|
||||
// 解析sector_data生成板块列表:剔除「其他」,格式[{title: 板块名, codes: 股票代码数组}]
|
||||
this.bkList = Object.entries(sector_data)
|
||||
.filter(([sectorName]) => sectorName !== '其他') // 去掉其他板块
|
||||
.map(([sectorName, sectorInfo]) => ({
|
||||
title: sectorName,
|
||||
codes: sectorInfo.stock_codes || [] // 取板块对应的股票代码
|
||||
}));
|
||||
|
||||
console.log('生成板块列表:', this.bkList);
|
||||
// 为股票添加角色标签
|
||||
this.setStockRoles();
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '数据请求失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('请求异常:', error);
|
||||
uni.showToast({
|
||||
title: '网络异常',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user