Files
JiaZhiQianYan/unpackage/dist/dev/mp-weixin/pagesStock/stockCenterDetails/bkydmx.js
2026-02-06 18:01:05 +08:00

362 lines
12 KiB
JavaScript
Raw 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 _sfc_main = {
data() {
return {
navH: common_vendor.inject("navHeight"),
contentTop: "",
activeIndex: 0,
bkList: [],
bkFilters: [
"按连板数",
"只看龙头"
],
filterIndex: 0,
selectedFullDate: "",
// 年-月-日
originData: null,
// 原始接口数据
allStocks: [],
// 所有股票数据(带角色标签)
// 角色配置
STOCK_ROLES: {
dragon: {
text: "龙头",
color: "#EC3440",
bgColor: "#FFE8E9",
icon: "/pagesStock/static/icon/first-icon1.png"
},
follow: {
text: "跟风",
color: "#F97316",
bgColor: "#FFF0E6",
icon: "/pagesStock/static/icon/first-icon2.png"
},
first: {
text: "首板",
color: "#01AB5D",
bgColor: "#E4F9EF",
icon: "/pagesStock/static/icon/first-icon.png"
},
normal: {
text: "",
color: "",
bgColor: "",
icon: ""
}
},
// 连板层级样式配置(新规则)
BOARD_LEVEL_STYLES: {
dragon: {
// 5板及以上 龙头
color: "#ef4444",
bgColor: "#FFE8E9",
borderColor: "#ef4444"
},
high: {
// 3-4板 高位
color: "#f97316",
bgColor: "#FFF0E6",
borderColor: "#f97316"
},
mid: {
// 2板 中位
color: "#eab308",
bgColor: "#FFF9E6",
borderColor: "#eab308"
},
first: {
// 1板 首板
color: "#22c55e",
bgColor: "#E4F9EF",
borderColor: "#22c55e"
}
},
// 板块文字颜色配置(新规则)
SECTOR_COLOR_RULES: [
{ keyword: "公告", color: "#D4AF37" },
// 金色
{ keyword: "其他", color: "#9CA3AF" },
// 灰色
{ keyword: ["AI", "人工智能", "芯片"], color: "#8B5CF6" },
// 紫色
{ keyword: ["锂电", "电池", "新能源"], color: "#10B981" },
// 翠绿
{ keyword: ["医药", "医疗"], color: "#EC4899" },
// 粉色
{ keyword: ["金融", "银行"], color: "#F59E0B" },
// 橙黄
{ keyword: ["军工", "航空"], color: "#EF4444" }
// 红色
],
DEFAULT_SECTOR_COLOR: "#06B6D4"
// 默认 青色
};
},
computed: {
// 筛选后的股票列表按板块codes匹配 + 连板排序/筛选
filteredStocks() {
var _a;
if (!((_a = this.originData) == null ? void 0 : _a.stocks) || !this.bkList.length)
return [];
const currentBk = this.bkList[this.activeIndex];
if (!(currentBk == null ? void 0 : currentBk.codes) || currentBk.codes.length === 0)
return [];
const targetCodes = new Set(currentBk.codes);
let stocks = this.originData.stocks.filter((stock) => targetCodes.has(stock.scode));
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:
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;
this.selectedFullDate = e.data;
common_vendor.index.__f__("log", "at pagesStock/stockCenterDetails/bkydmx.vue:229", "selectedFullDate", this.selectedFullDate);
this.contentTop = this.navH + 20 / 750 * common_vendor.inject("windowWidth");
this.fetchData();
},
methods: {
// 解析连板数
parseContinuousDays(continuousDaysStr) {
if (!continuousDaysStr)
return 0;
const match = continuousDaysStr.match(/(\d+)天/);
return match ? Number(match[1]) : 0;
},
// 格式化连板文本(适配新层级)
formatBoardText(continuousDaysStr) {
const boardDays = this.parseContinuousDays(continuousDaysStr);
if (boardDays === 1)
return "首板";
if (boardDays > 1)
return `${boardDays}连板`;
return "";
},
// 获取连板标签样式(按新层级规则)
getBoardTagStyleByLevel(continuousDaysStr) {
const boardDays = this.parseContinuousDays(continuousDaysStr);
let styleConfig = {};
if (boardDays >= 5) {
styleConfig = this.BOARD_LEVEL_STYLES.dragon;
} else if (boardDays >= 3 && boardDays <= 4) {
styleConfig = this.BOARD_LEVEL_STYLES.high;
} else if (boardDays === 2) {
styleConfig = this.BOARD_LEVEL_STYLES.mid;
} else if (boardDays === 1) {
styleConfig = this.BOARD_LEVEL_STYLES.first;
}
return {
"color": styleConfig.color || "#FFFFFF",
"background-color": styleConfig.bgColor || "#eab308",
"border": `1rpx solid ${styleConfig.borderColor || "#eab308"}`
};
},
// 获取板块文字颜色(按关键词匹配)
getSectorTextColor(sectorName) {
if (!sectorName)
return this.DEFAULT_SECTOR_COLOR;
for (const rule of this.SECTOR_COLOR_RULES) {
if (Array.isArray(rule.keyword)) {
const isMatch = rule.keyword.some((key) => sectorName.includes(key));
if (isMatch)
return rule.color;
} else {
if (sectorName === rule.keyword)
return rule.color;
}
}
return this.DEFAULT_SECTOR_COLOR;
},
// 获取股票角色
getStockRole(stock, sectorStocks, sectorIndex) {
var _a;
const boardDays = this.parseContinuousDays(stock.continuous_days);
if (boardDays >= 5) {
return this.STOCK_ROLES.dragon;
}
if (boardDays === 1) {
return this.STOCK_ROLES.first;
}
if (sectorIndex < 3 && boardDays >= 2 && boardDays < 5) {
const sortedByTime = [...sectorStocks].sort(
(a, b) => (a.zt_time || "").localeCompare(b.zt_time || "")
);
if (((_a = sortedByTime[0]) == null ? void 0 : _a.scode) === stock.scode && boardDays >= 3) {
return this.STOCK_ROLES.dragon;
}
return this.STOCK_ROLES.follow;
}
return this.STOCK_ROLES.normal;
},
// 获取角色标签样式
getRoleTagStyle(role) {
return {
"background-color": role.bgColor
};
},
// 处理板块切换
handleTabChange(index) {
this.activeIndex = index;
this.setStockRoles();
},
// 处理筛选切换
handleFilterChange(index) {
this.filterIndex = index;
},
// 为所有股票添加角色标签
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 = (/* @__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 pagesStock/stockCenterDetails/bkydmx.vue:390", "请求URL", requestUrl);
const res = await common_vendor.index.request({
url: requestUrl,
method: "GET"
});
if (res.statusCode === 200 && res.data) {
this.originData = res.data;
const { sector_data } = this.originData;
this.bkList = Object.entries(sector_data).filter(([sectorName]) => sectorName !== "其他").map(([sectorName, sectorInfo]) => ({
title: sectorName,
codes: sectorInfo.stock_codes || []
// 取板块对应的股票代码
}));
common_vendor.index.__f__("log", "at pagesStock/stockCenterDetails/bkydmx.vue:408", "生成板块列表:", this.bkList);
this.setStockRoles();
} else {
common_vendor.index.showToast({
title: "数据请求失败",
icon: "none"
});
}
} catch (error) {
common_vendor.index.__f__("error", "at pagesStock/stockCenterDetails/bkydmx.vue:418", "请求异常:", error);
common_vendor.index.showToast({
title: "网络异常",
icon: "none"
});
}
}
}
};
if (!Array) {
const _easycom_navBar2 = common_vendor.resolveComponent("navBar");
_easycom_navBar2();
}
const _easycom_navBar = () => "../../components/navBar/navBar.js";
if (!Math) {
_easycom_navBar();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return {
a: common_vendor.p({
leftText: "板块异动明细",
hideNavBg: true
}),
b: common_assets._imports_0,
c: common_vendor.f($data.bkList, (item, index, i0) => {
return {
a: common_vendor.t(item.title),
b: "tab-" + index,
c: common_vendor.o(($event) => $data.activeIndex = index, index),
d: index,
e: $data.activeIndex == index ? "#2B2B2B" : "#999999",
f: $data.activeIndex == index ? "1rpx solid #F2C369" : "none",
g: $data.activeIndex == index ? "28rpx" : "26rpx"
};
}),
d: "tab-" + $data.activeIndex,
e: common_vendor.f($data.bkFilters, (item, index, i0) => {
return {
a: common_vendor.t(item),
b: common_vendor.o(($event) => $options.handleFilterChange(index), index),
c: $data.filterIndex == index ? "#070707" : "#939393",
d: $data.filterIndex == index ? "1rpx solid #F2C369" : "1rpx solid #E5E5E5",
e: $data.filterIndex == index ? "#F2C369" : "#fff",
f: index
};
}),
f: common_vendor.f(["名称", "涨幅", "连板", "板块"], (item, index, i0) => {
return {
a: common_vendor.t(item),
b: index,
c: index == 0 ? "left" : "center"
};
}),
g: common_vendor.f($options.filteredStocks, (item, index, i0) => {
return common_vendor.e({
a: item.stockRole
}, item.stockRole ? common_vendor.e({
b: item.stockRole.icon
}, item.stockRole.icon ? {
c: item.stockRole.icon
} : {}, {
d: common_vendor.t(item.stockRole.text),
e: item.stockRole.color,
f: common_vendor.s($options.getRoleTagStyle(item.stockRole))
}) : {}, {
g: common_vendor.t(item.sname),
h: common_vendor.t($options.formatBoardText(item.continuous_days)),
i: common_vendor.s($options.getBoardTagStyleByLevel(item.continuous_days)),
j: common_vendor.t(item.core_sectors[0] || "未知板块"),
k: $options.getSectorTextColor(item.core_sectors[0] || "未知板块"),
l: item.scode,
m: index % 2 == 0 ? "#fff" : "#FAFAFC"
});
}),
h: 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/pagesStock/stockCenterDetails/bkydmx.js.map