Files
2026-02-06 18:01:05 +08:00

788 lines
24 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
const common_vendor = require("../../common/vendor.js");
const request_http = require("../../request/http.js");
const common_assets = require("../../common/assets.js");
const echarts = require("../../uni_modules/lime-echart/static/echarts.min.js");
const WordCloud = () => "../../components/WordCloud/WordCloud2.js";
const mockGraphData = {
categories: [
{
name: "板块"
},
{
name: "概念"
},
{
name: "个股"
}
],
nodes: [
{
name: "科技板块",
symbolSize: 50,
category: 0
},
{
name: "人工智能",
symbolSize: 30,
category: 1
},
{
name: "大数据",
symbolSize: 25,
category: 1
},
{
name: "科大讯飞",
symbolSize: 20,
category: 2
},
{
name: "百度",
symbolSize: 20,
category: 2
},
{
name: "金融板块",
symbolSize: 50,
category: 0
},
{
name: "数字货币",
symbolSize: 30,
category: 1
},
{
name: "招商银行",
symbolSize: 20,
category: 2
},
{
name: "平安银行",
symbolSize: 20,
category: 2
}
],
links: [
{
source: "科技板块",
target: "人工智能",
value: 10
},
{
source: "科技板块",
target: "大数据",
value: 8
},
{
source: "人工智能",
target: "科大讯飞",
value: 6
},
{
source: "人工智能",
target: "百度",
value: 6
},
{
source: "金融板块",
target: "数字货币",
value: 9
},
{
source: "数字货币",
target: "招商银行",
value: 5
},
{
source: "数字货币",
target: "平安银行",
value: 5
}
]
};
const _sfc_main = {
components: {
WordCloud
},
data() {
return {
navH: common_vendor.inject("navHeight"),
contentTop: "",
selectedYearMonth: "",
// 年-月(去掉日)
selectedFullDate: "",
// 年-月-日
selectedItem: null,
// 选中的item完整数据
tabTypes: [
{
data: "",
change: 0,
title: "当前日期"
},
{
data: "",
change: 3,
title: "涨停家数"
},
{
data: "22%",
change: 0,
title: "炸板率"
}
],
wordData: [],
bkList: [],
number_limit_stocks: "",
HEAT_LEVELS: [
{
threshold: 0.7,
color: "#EF4444",
level: "高热度"
},
// >70%
{
threshold: 0.4,
color: "#F97316",
level: "中热度"
},
// 40%~70%
{
threshold: 0.2,
color: "#F3B800",
level: "低热度"
},
// 20%~40%
{
threshold: 0,
color: "#01AB5D",
level: "无热度"
}
// ≤20%
],
// bkTypes: [
// '板块关联图',
// '板块分布',
// '热门概念词云'
// ],
highPositionStats: {
total_count: 0,
// 高位股数量
avg_continuous_days: 0,
// 平均连板数
max_continuous_days: 0
// 最高连板数
},
riskAssessment: {
// 风险评估结果
level: "正常",
color: "#22c55e"
},
highPositionStockList: [],
// 新增:存储筛选后的高位股列表
// 风险阈值常量(对应参考代码)
RISK_THRESHOLDS: {
CRITICAL: 7,
HIGH: 5,
MEDIUM: 3,
LOW: 2
},
// 风险颜色常量
RISK_COLORS: {
critical: {
color: "#ef4444",
bg: "rgba(239, 68, 68, 0.2)",
border: "rgba(239, 68, 68, 0.4)"
},
high: {
color: "#f97316",
bg: "rgba(249, 115, 22, 0.2)",
border: "rgba(249, 115, 22, 0.4)"
},
medium: {
color: "#eab308",
bg: "rgba(234, 179, 8, 0.2)",
border: "rgba(234, 179, 8, 0.4)"
},
low: {
color: "#22c55e",
bg: "rgba(34, 197, 94, 0.2)",
border: "rgba(34, 197, 94, 0.4)"
}
},
heatIconMap: {
high: {
icon4: "/pagesStock/static/icon/all-icon-4.png",
icon4Color: "#EF4444",
// 高热度图标颜色
icon5: "/pagesStock/static/icon/all-icon-5.png"
// 高热度右侧图标
},
medium: {
icon4: "/pagesStock/static/icon/all-icon-9.png",
icon4Color: "#F97316",
// 中热度图标颜色
icon5: "/pagesStock/static/icon/all-icon-6.png"
// 中热度右侧图标
},
low: {
icon4: "",
// 低热度不显示icon4
icon4Color: "#F3B800",
icon5: "/pagesStock/static/icon/all-icon-7.png"
// 低热度右侧图标
},
none: {
icon4: "",
// 冷门
icon4Color: "#01AB5D",
icon5: "/pagesStock/static/icon/all-icon-8.png"
// 无热度右侧图标
}
},
originData: null,
// 原始接口数据
bkTypes: [
"板块分布",
"热门概念词云"
],
activeType: 0,
// 默认选中第一个标签
// 饼图配置项
pieOption: {
tooltip: {
trigger: "item"
},
animation: false,
legend: {
top: "5%",
left: "center",
show: false
},
series: [{
name: "Access From",
type: "pie",
radius: ["40%", "70%"],
avoidLabelOverlap: false,
padAngle: 2,
itemStyle: {
borderRadius: 8
},
emphasis: {
label: {
show: true,
fontSize: 10
}
},
labelLine: {
length: 1,
length2: 5
},
data: []
}]
},
// 关系图配置项
graphOption: {
tooltip: {},
legend: [],
series: [{
name: "板块关联",
type: "graph",
layout: "none",
data: [],
links: [],
categories: [],
roam: true,
// 允许拖拽和缩放
label: {
show: true,
position: "right",
formatter: "{b}"
},
labelLayout: {
hideOverlap: true
},
scaleLimit: {
min: 0.4,
max: 2
},
lineStyle: {
color: "source",
curveness: 0.3
}
}]
}
};
},
onLoad(e) {
this.activeIndex = e.index;
this.contentTop = this.navH + 20 / 750 * common_vendor.inject("windowWidth");
},
onReady() {
},
methods: {
// 词云绘制完成
onWordCloudRendered() {
common_vendor.index.hideLoading();
},
getStockHeatType(stock) {
const days = stock.continuous_days_num || 0;
if (days >= this.RISK_THRESHOLDS.CRITICAL) {
return "high";
} else if (days >= this.RISK_THRESHOLDS.HIGH) {
return "medium";
} else if (days >= this.RISK_THRESHOLDS.MEDIUM) {
return "low";
} else {
return "none";
}
},
//解析连板数(从"2天2板"格式中提取数字)
parseContinuousDays(continuousDaysStr) {
if (!continuousDaysStr)
return 0;
const match = continuousDaysStr.match(/(\d+)天/);
return match ? Number(match[1]) : 0;
},
// 风险等级判断函数
getRiskLevel(days) {
const {
RISK_THRESHOLDS,
RISK_COLORS
} = this;
if (days >= RISK_THRESHOLDS.CRITICAL) {
return {
level: "极高",
color: RISK_COLORS.critical.color,
bg: RISK_COLORS.critical.bg,
border: RISK_COLORS.critical.border,
status: "缩量一字,高风险"
};
}
if (days >= RISK_THRESHOLDS.HIGH) {
return {
level: "高",
color: RISK_COLORS.high.color,
bg: RISK_COLORS.high.bg,
border: RISK_COLORS.high.border,
status: "放量分歧,需观察"
};
}
if (days >= RISK_THRESHOLDS.MEDIUM) {
return {
level: "中",
color: RISK_COLORS.medium.color,
bg: RISK_COLORS.medium.bg,
border: RISK_COLORS.medium.border,
status: "正常波动"
};
}
return {
level: "低",
color: RISK_COLORS.low.color,
bg: RISK_COLORS.low.bg,
border: RISK_COLORS.low.border,
status: "健康"
};
},
// 计算高位股统计数据
calculateHighPositionStats() {
if (!this.originData || !this.originData.stocks)
return;
const highPositionStocks = this.originData.stocks.filter((stock) => {
const days = this.parseContinuousDays(stock.continuous_days);
return days >= 2;
}).map((stock) => {
const days = this.parseContinuousDays(stock.continuous_days);
const riskInfo = this.getRiskLevel(days);
return {
...stock,
continuous_days_num: days,
// 提取纯数字的连板数
risk_info: riskInfo
// 风险等级信息
};
}).sort((a, b) => b.continuous_days_num - a.continuous_days_num);
this.highPositionStockList = highPositionStocks;
const totalCount = highPositionStocks.length;
const maxDays = highPositionStocks.length ? Math.max(...highPositionStocks.map((s) => this.parseContinuousDays(s.continuous_days))) : 0;
const totalDays = highPositionStocks.reduce((sum, stock) => {
return sum + this.parseContinuousDays(stock.continuous_days);
}, 0);
const avgDays = totalCount > 0 ? (totalDays / totalCount).toFixed(1) : 0;
this.highPositionStats = {
total_count: totalCount,
avg_continuous_days: avgDays,
max_continuous_days: maxDays
};
this.calculateRiskAssessment();
},
// 计算风险评估
calculateRiskAssessment() {
const {
avg_continuous_days,
max_continuous_days,
total_count
} = this.highPositionStats;
const avgDays = Number(avg_continuous_days) || 0;
const maxDays = Number(max_continuous_days) || 0;
const totalCount = Number(total_count) || 0;
const score = avgDays * 2 + maxDays * 0.5 + totalCount * 0.3;
if (score >= 20) {
this.riskAssessment = {
level: "高风险",
color: "#ef4444"
};
} else if (score >= 12) {
this.riskAssessment = {
level: "中风险",
color: "#f97316"
};
} else if (score >= 6) {
this.riskAssessment = {
level: "偏高",
color: "#eab308"
};
} else {
this.riskAssessment = {
level: "正常",
color: "#22c55e"
};
}
},
getHeatColor(value, max) {
if (max === 0)
return "#01AB5D";
const ratio = value / max;
const matchedLevel = this.HEAT_LEVELS.find((level) => ratio > level.threshold);
return matchedLevel ? matchedLevel.color : "#01AB5D";
},
// 切换标签
async switchTab(index) {
this.activeType = index;
switch (index) {
case 0:
this.$refs.chartRef && this.initPieChart();
break;
case 1:
common_vendor.index.showLoading({
title: "词云生成中...",
mask: true
// 防止用户误触
});
this.initWordCloud();
break;
case 2:
common_vendor.index.showLoading({
title: "词云生成中...",
mask: true
// 防止用户误触
});
this.initWordCloud();
break;
}
},
getPreviousDayDate() {
const now = /* @__PURE__ */ new Date();
const currentYear = now.getFullYear();
const currentMonth = String(now.getMonth() + 1).padStart(2, "0");
const currentDay = String(now.getDate()).padStart(2, "0");
const dateStr = `${currentYear}-${currentMonth}-${currentDay}`;
if (!/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) {
common_vendor.index.__f__("error", "at pages/ztfx/ztfx.vue:763", "日期格式错误,请传入 YYYY-MM-DD 格式的日期");
return "";
}
const [year, month, day] = dateStr.split("-").map(Number);
const date = new Date(year, month - 1, day);
date.setDate(date.getDate() - 1);
const prevYear = date.getFullYear();
const prevMonth = String(date.getMonth() + 1).padStart(2, "0");
const prevDay = String(date.getDate()).padStart(2, "0");
return `${prevYear}${prevMonth}${prevDay}`;
},
/**
* 请求接口数据(优化:动态日期+自动时间戳)
*/
async fetchData() {
try {
const timestamp = (/* @__PURE__ */ new Date()).getTime();
const formattedDate = this.selectedFullDate;
const baseURL = request_http.getBaseURL1();
const requestUrl = `${baseURL}/data/zt/daily/${formattedDate}.json?t=${timestamp}`;
common_vendor.index.__f__("log", "at pages/ztfx/ztfx.vue:796", "请求URL", requestUrl);
const res = await common_vendor.index.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;
let bkList = [];
const maxLen = Math.min(labels.length, counts.length);
for (let i = 0; i < maxLen; i++) {
const title = labels[i];
const count = counts[i] || 0;
const bgColor = this.getHeatColor(count, maxCount);
const ratio = maxCount === 0 ? 0 : (count / maxCount * 100).toFixed(2);
bkList.push({
title,
// 板块名称
count,
// 数量
bgColor,
// 背景色
ratio
// 占比(百分比,可选)
});
}
this.bkList = bkList.slice(0, 16);
this.initPieChart();
this.calculateHighPositionStats();
} else {
common_vendor.index.showToast({
title: "数据请求失败",
icon: "none"
});
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/ztfx/ztfx.vue:846", "请求异常:", error);
common_vendor.index.showToast({
title: "网络异常",
icon: "none"
});
}
},
// 初始化关系图(增加容错)
async initGraphChart() {
const chart = await this.$refs.graphChartRef.init(echarts);
this.graphOption.legend = [{
data: mockGraphData.categories.map((a) => a.name)
}];
this.graphOption.series[0].data = mockGraphData.nodes;
this.graphOption.series[0].links = mockGraphData.links;
this.graphOption.series[0].categories = mockGraphData.categories;
chart.setOption(this.graphOption);
},
// 初始化饼图(核心修复)
async initPieChart() {
try {
let pieData = [];
const chartData = this.originData.chart_data || {};
const labels = chartData.labels || [];
const counts = chartData.counts || [];
const maxLen = Math.min(labels.length, counts.length);
for (let i = 0; i < maxLen; i++) {
pieData.push({
name: labels[i],
// 板块名称
value: counts[i]
// 对应数量
});
}
this.pieOption.series[0].data = pieData.length > 0 ? pieData : [
{
value: 10,
name: "科技板块"
},
{
value: 8,
name: "人脑工程"
},
{
value: 9,
name: "商业航天"
}
];
if (this.$refs.chartRef) {
const Piechart = await this.$refs.chartRef.init(echarts);
common_vendor.index.__f__("log", "at pages/ztfx/ztfx.vue:907", "Piechart实例创建成功", Piechart);
Piechart.setOption(this.pieOption);
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/ztfx/ztfx.vue:911", "饼图初始化失败:", error);
}
},
// 初始化词云
initWordCloud() {
if (this.originData.word_freq_data && Array.isArray(this.originData.word_freq_data)) {
this.wordData = this.originData.word_freq_data;
common_vendor.index.__f__("log", "at pages/ztfx/ztfx.vue:920", "词云数据赋值完成", this.wordData);
} else {
this.wordData = [{
name: "脑机",
value: 1e4
}, {
name: "航天",
value: 3428
}];
}
setTimeout(() => {
common_vendor.index.hideLoading();
}, 2e3);
},
handleDateChange(data) {
var _a, _b, _c, _d;
common_vendor.index.__f__("log", "at pages/ztfx/ztfx.vue:940", "从日历组件接收的参数:", {
currentZtCount: (_a = data.item) == null ? void 0 : _a.zt_count,
prevZtCount: (_b = data.prevItem) == null ? void 0 : _b.zt_count
});
this.selectedYearMonth = data.yearMonth;
this.selectedFullDate = data.fullDate ? data.fullDate.replace(/-/g, "") : "";
this.selectedItem = data.item;
if (data.fullDate) {
const [year, month, day] = data.fullDate.split("-").map(Number);
this.tabTypes[0].data = `${month}${day}`;
}
const ztCount = ((_c = data.item) == null ? void 0 : _c.zt_count) ?? 0;
this.tabTypes[1].data = ztCount.toString();
this.number_limit_stocks = ztCount.toString();
const prevZtCount = ((_d = data.prevItem) == null ? void 0 : _d.zt_count) ?? 0;
const changeValue = ztCount === 0 || prevZtCount === 0 ? 0 : ztCount - prevZtCount;
this.tabTypes[1].change = changeValue;
if (this.selectedFullDate) {
const today = /* @__PURE__ */ new Date();
const todayYear = today.getFullYear();
const todayMonth = String(today.getMonth() + 1).padStart(2, "0");
const todayDay = String(today.getDate()).padStart(2, "0");
const todayFormatted = `${todayYear}${todayMonth}${todayDay}`;
if (this.selectedFullDate === todayFormatted) {
const selectedDate = new Date(
parseInt(this.selectedFullDate.substring(0, 4)),
// 年
parseInt(this.selectedFullDate.substring(4, 6)) - 1,
// 月月份从0开始
parseInt(this.selectedFullDate.substring(6, 8))
// 日
);
selectedDate.setDate(selectedDate.getDate() - 1);
const prevYear = selectedDate.getFullYear();
const prevMonth = String(selectedDate.getMonth() + 1).padStart(2, "0");
const prevDay = String(selectedDate.getDate()).padStart(2, "0");
const prevDateFormatted = `${prevYear}${prevMonth}${prevDay}`;
this.selectedFullDate = prevDateFormatted;
common_vendor.index.__f__("log", "at pages/ztfx/ztfx.vue:998", `选中日期为当天(${todayFormatted}),已自动调整为前一天:`, prevDateFormatted);
}
}
this.fetchData();
},
bkydAction(index) {
common_vendor.index.navigateTo({
url: `/pagesStock/stockCenterDetails/bkydmx?index=${index}&data=${this.selectedFullDate}`
});
}
}
};
if (!Array) {
const _easycom_navBar2 = common_vendor.resolveComponent("navBar");
const _easycom_LCCalendar2 = common_vendor.resolveComponent("LCCalendar");
const _easycom_l_echart2 = common_vendor.resolveComponent("l-echart");
const _easycom_WordCloud2 = common_vendor.resolveComponent("WordCloud");
(_easycom_navBar2 + _easycom_LCCalendar2 + _easycom_l_echart2 + _easycom_WordCloud2)();
}
const _easycom_navBar = () => "../../components/navBar/navBar.js";
const _easycom_LCCalendar = () => "../../components/LCCalendar/LCCalendar.js";
const _easycom_l_echart = () => "../../uni_modules/lime-echart/components/l-echart/l-echart.js";
const _easycom_WordCloud = () => "../../components/WordCloud/WordCloud2.js";
if (!Math) {
(_easycom_navBar + _easycom_LCCalendar + _easycom_l_echart + _easycom_WordCloud)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return {
a: common_vendor.p({
leftText: "涨停分析",
hideNavBg: true,
hideBack: true
}),
b: common_assets._imports_0,
c: common_assets._imports_1$9,
d: common_assets._imports_2$9,
e: common_vendor.f($data.tabTypes, (item, index, i0) => {
return common_vendor.e({
a: common_vendor.t(item.data),
b: item.change !== 0
}, item.change !== 0 ? {
c: common_vendor.t(item.change > 0 ? "+" + item.change : item.change),
d: common_vendor.s({
marginLeft: "10rpx",
borderRadius: "5rpx",
color: "white",
padding: "0 5rpx",
fontSize: "24rpx",
fontWeight: "bold"
}),
e: common_vendor.s(item.change > 0 ? {
backgroundColor: "#F59B38"
} : {
backgroundColor: "#EF4444"
})
} : {}, {
f: common_vendor.t(item.title),
g: index
});
}),
f: common_vendor.o($options.handleDateChange),
g: common_assets._imports_3$8,
h: common_vendor.t($data.bkList.length),
i: common_vendor.t($data.number_limit_stocks),
j: common_vendor.f($data.bkList, (item, index, i0) => {
return {
a: common_vendor.t(item.title),
b: common_vendor.t(item.count),
c: index,
d: item.bgColor,
e: common_vendor.o(($event) => $options.bkydAction(index), index)
};
}),
k: common_vendor.f($data.bkTypes, (item, index, i0) => {
return {
a: common_vendor.t(item),
b: common_vendor.o(($event) => $options.switchTab(index)),
c: $data.activeType == index ? "#BB8520" : "#999999",
d: `1rpx solid ${$data.activeType == index ? "#F2C369" : "#D2D2D2"}`,
e: $data.activeType == index ? "#FFFAF1" : "#FFF"
};
}),
l: common_vendor.sr("chartRef", "06b829a4-2"),
m: $data.activeType === 0,
n: $data.activeType === 1,
o: common_vendor.o($options.onWordCloudRendered),
p: common_vendor.p({
wordData: $data.wordData,
width: 330,
height: 330
}),
q: common_assets._imports_3$8,
r: common_vendor.t($data.highPositionStats.total_count),
s: common_vendor.t($data.highPositionStats.avg_continuous_days),
t: common_vendor.t($data.highPositionStats.max_continuous_days),
v: common_vendor.t($data.riskAssessment.level),
w: $data.riskAssessment.color,
x: common_vendor.f($data.highPositionStockList, (stock, index, i0) => {
return common_vendor.e({
a: common_vendor.t(stock.sname),
b: common_vendor.t(stock.risk_info.status),
c: ["high", "medium"].includes($options.getStockHeatType(stock))
}, ["high", "medium"].includes($options.getStockHeatType(stock)) ? {
d: $data.heatIconMap[$options.getStockHeatType(stock)].icon4Color,
e: $data.heatIconMap[$options.getStockHeatType(stock)].icon4
} : {}, {
f: common_vendor.t(stock.continuous_days_num),
g: stock.risk_info.bg,
h: `1rpx solid ${stock.risk_info.border}`,
i: stock.risk_info.color,
j: $data.heatIconMap[$options.getStockHeatType(stock)].icon5,
k: index
});
}),
y: common_assets._imports_5$4,
z: common_vendor.s("top:" + $data.contentTop + "px;")
};
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/ztfx/ztfx.js.map