Files
JiaZhiQianYan/unpackage/dist/dev/mp-weixin/pages/geGuCenter/geGuCenter.js

573 lines
21 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_api = require("../../request/api.js");
const common_assets = require("../../common/assets.js");
const _sfc_main = {
data() {
return {
navH: common_vendor.inject("navHeight"),
contentTop: "",
currentDate: "",
// 最终要赋值的日期
selectedDate: "",
// 临时存储选中的日期
allStockData: [],
filteredData: [],
conceptStocksList: [],
alertTypeConfig: {
"surge": {
text: "异动",
color: "#FF7A45",
// rgb(255, 122, 69)
filter: "brightness(0) saturate(100%) invert(54%) sepia(60%) saturate(467%) hue-rotate(344deg) brightness(102%) contrast(101%)"
},
"shrink_surge_up": {
text: "缩量急涨",
color: "#722ED1",
// rgb(114, 46, 209)
filter: "brightness(0) saturate(100%) invert(24%) sepia(90%) saturate(2865%) hue-rotate(266deg) brightness(87%) contrast(98%)"
},
"volume_surge_up": {
text: "放量急涨",
color: "#EB2F96",
// rgb(235, 47, 150)
filter: "brightness(0) saturate(100%) invert(34%) sepia(82%) saturate(1970%) hue-rotate(313deg) brightness(91%) contrast(94%)"
},
"volume_oscillation": {
text: "放量震荡",
color: "#13C2C2",
// rgb(19, 194, 194)
filter: "brightness(0) saturate(100%) invert(71%) sepia(62%) saturate(487%) hue-rotate(142deg) brightness(91%) contrast(93%)"
},
"surge_up": {
text: "急涨",
color: "#FF4D4F",
// rgb(255, 77, 79)
filter: "brightness(0) saturate(100%) invert(42%) sepia(93%) saturate(727%) hue-rotate(346deg) brightness(102%) contrast(104%)"
},
"surge_down": {
text: "急跌",
color: "#52C41A",
// rgb(82, 196, 26)
filter: "brightness(0) saturate(100%) invert(68%) sepia(65%) saturate(456%) hue-rotate(71deg) brightness(91%) contrast(86%)"
},
"shrink_surge_down": {
text: "缩量急跌",
color: "#FF7A45",
// rgb(255, 122, 69)
filter: "brightness(0) saturate(100%) invert(54%) sepia(60%) saturate(467%) hue-rotate(344deg) brightness(102%) contrast(101%)"
}
},
topLists: [
{
title: "大盘涨跌幅",
value: "+0.00%",
color: "#EC3440",
backIcon: "/static/icon/gegu/gg-top-0.png"
},
{
title: "涨停/跌停",
value: "+0.00%",
color: "#070707",
backIcon: "/static/icon/gegu/gg-top-1.png"
},
{
title: "多空对比",
value: "0/0",
color: "#070707",
backIcon: "/static/icon/gegu/gg-top-2.png"
},
{
title: "今日成交额",
value: "0万亿",
color: "#070707",
backIcon: "/static/icon/gegu/gg-top-3.png"
},
{
title: "A股总市值",
value: "0万亿",
color: "#070707",
backIcon: "/static/icon/gegu/gg-top-4.png"
},
{
title: "连板龙头",
value: "0只",
color: "#F59B38",
backIcon: "/static/icon/gegu/gg-top-5.png"
}
],
topLists2: [
{
title: "超大盘股",
value: ">1000亿"
},
{
title: "大盘股",
value: "500-1000亿"
},
{
title: "中盘股",
value: "100-500亿"
}
],
list2Index: 0,
typeList: [
{
title: "缩量急涨",
backIcon: "/static/icon/gegu/cate-0.png"
},
{
title: "异动",
backIcon: "/static/icon/gegu/cate-1.png"
},
{
title: "急跌",
backIcon: "/static/icon/gegu/cate-2.png"
},
{
title: "急涨",
backIcon: "/static/icon/gegu/cate-3.png"
},
{
title: "放量震荡",
backIcon: "/static/icon/gegu/cate-4.png"
}
],
marketAlertsList: [],
formattedAvg: 0,
upCount: 0,
downCount: 0,
limit_up_ratio: 0
};
},
onLoad(e) {
this.activeIndex = e.index;
this.contentTop = this.navH + (20 + 70 + 25) / 750 * common_vendor.inject("windowWidth");
const now = /* @__PURE__ */ 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}`;
},
onShow() {
this.marketHeatmap();
this.marketStatistics();
this.marketHotspotListOverview();
},
methods: {
formatAlpha(value) {
if (value === null || value === void 0 || isNaN(Number(value))) {
return "0.0";
}
return Number(value).toFixed(1);
},
handleTypeClick(index) {
this.list2Index = index;
this.marketHeatmap(this.currentDate);
},
getTableItem(obj) {
const marketCap = obj.market_cap ? obj.market_cap.toFixed(2) : "0.00";
const amount = obj.amount ? obj.amount.toFixed(2) : "0.00";
const changePercent = obj.change_percent ? Number(obj.change_percent) : 0;
let changePercentStr = "";
let changeType = "";
if (changePercent > 0) {
changePercentStr = `+${changePercent}%`;
changeType = "positive";
} else if (changePercent < 0) {
changePercentStr = `${changePercent}%`;
changeType = "negative";
} else {
changePercentStr = "0%";
changeType = "zero";
}
return [
[obj.stock_name, obj.stock_code],
[changePercentStr, "", changeType],
// 第三个元素存类型标记
[`${marketCap}亿元`],
[`${amount}亿元`],
[obj.industry || "暂无"]
// 处理行业为空的情况
];
},
// 处理涨停比:转百分比 + 四舍五入(可指定保留小数位数)
formatLimitUpRatio(value, decimalPlaces = 0) {
if (!value || isNaN(Number(value))) {
return "0%";
}
const percentValue = Number(value) * 100;
const result = decimalPlaces === 0 ? Math.round(percentValue) : percentValue.toFixed(decimalPlaces);
return `${result}%`;
},
conceptsDailyTop() {
request_api.conceptsDailyTop().then((res) => {
}).catch((error) => {
});
},
marketHeatmap(currentDate) {
let param = {
limit: 500
};
if (currentDate && currentDate !== "undefined" && currentDate.trim() !== "") {
param.date = currentDate;
}
request_api.marketHeatmap(param).then((res) => {
this.topLists[2].value = res.statistics.rising_count + "/" + res.statistics.falling_count;
this.allStockData = res.data || [];
const limitUpCount = this.allStockData.filter((s) => {
const changePercent = Number(s.change_percent);
return !isNaN(changePercent) && changePercent >= 9.9;
}).length;
const limitDownCount = this.allStockData.filter((s) => {
const changePercent = Number(s.change_percent);
return !isNaN(changePercent) && changePercent <= -9.9;
}).length;
this.topLists[1].value = limitUpCount + "/" + limitDownCount;
this.topLists[5].value = limitUpCount + "只";
this.filterStockByMarketCap();
}).catch((error) => {
});
},
// 根据市值区间筛选数据
filterStockByMarketCap() {
const {
list2Index,
allStockData
} = this;
let filtered = [];
switch (list2Index) {
case 0:
filtered = allStockData.filter((item) => item.market_cap > 1e3);
break;
case 1:
filtered = allStockData.filter((item) => item.market_cap >= 500 && item.market_cap <= 1e3);
break;
case 2:
filtered = allStockData.filter((item) => item.market_cap >= 100 && item.market_cap <= 500);
break;
default:
filtered = allStockData;
}
this.filteredData = filtered.slice(0, 10);
},
marketStatistics() {
request_api.marketStatistics().then((res) => {
this.topLists[3].value = this.formatToTrillion(res.summary.total_amount);
this.topLists[4].value = this.formatToTrillion(res.summary.total_market_cap);
}).catch((error) => {
this.topLists[3].value = "0.0 万亿";
this.topLists[4].value = "0.0 万亿";
});
},
formatToTrillion(num) {
if (typeof num !== "number" || isNaN(num)) {
return "0.0 万亿";
}
const trillionValue = (num / 1e4).toFixed(1);
return `${trillionValue} 万亿`;
},
marketHotspotListOverview() {
let param = {
date: this.currentDate
};
request_api.marketHotspotOverview(param).then((res) => {
var _a;
const alerts = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.alerts) || [];
const changePct = res.data.index.change_pct;
let numPct = 0;
if (changePct && !isNaN(Number(changePct))) {
numPct = Number(changePct);
}
const roundedPct = Math.round(numPct * 100) / 100;
const fixedPct = roundedPct.toFixed(2);
let formattedPct = "";
if (roundedPct > 0) {
formattedPct = `+${fixedPct}%`;
} else if (roundedPct < 0) {
formattedPct = `${fixedPct}%`;
} else {
formattedPct = "0.00%";
}
const color = roundedPct > 0 ? "#EC3440" : roundedPct < 0 ? "#01AB5D" : "#666666";
this.topLists[0].value = formattedPct;
this.topLists[0].color = color;
const processedAlerts = alerts.map((alertItem) => {
const stocks = alertItem.stocks || [];
const validStocks = stocks.filter((s) => s.change_pct != null && !isNaN(Number(s.change_pct)));
const avgChange = validStocks.length > 0 ? validStocks.reduce((sum, s) => sum + Number(s.change_pct), 0) / validStocks.length : 0;
const upCount = validStocks.filter((s) => Number(s.change_pct) > 0).length;
const downCount = validStocks.filter((s) => Number(s.change_pct) < 0).length;
const roundedAvg = Math.round(avgChange * 100) / 100;
const formattedAvg = roundedAvg > 0 ? `+${roundedAvg.toFixed(2)}` : roundedAvg.toFixed(2);
return {
...alertItem,
alpha: avgChange,
// 供模板中判断颜色和显示数值
upCount,
// 上涨股票数
downCount,
// 下跌股票数
formattedAvg
// 格式化后的均涨值(带正负号)
};
});
const sortByTimeDesc = (a, b) => {
const timeToMinutes = (timeStr) => {
const [hours, minutes] = timeStr.split(":").map(Number);
return hours * 60 + minutes;
};
const minutesA = timeToMinutes(a.time);
const minutesB = timeToMinutes(b.time);
return minutesB - minutesA;
};
const sortedAlerts = processedAlerts.sort(sortByTimeDesc);
this.marketAlertsList = sortedAlerts;
}).catch((error) => {
});
},
itemDetails(item) {
common_vendor.index.navigateTo({
url: "/pagesStock/stockCenterDetails/stockCenterDetails?code=" + item.stock_code
});
},
moreAction() {
common_vendor.index.navigateTo({
url: "/pages/geGuCenter/detail?currentDate=" + this.currentDate
});
},
allAction(index) {
if (index == 1) {
this.$refs["typePopup"].open();
} else if (index == 2) {
this.$refs["datePopup"].open();
}
},
closeAction(index) {
if (index == 1) {
this.$refs["typePopup"].close();
} else if (index == 2) {
this.$refs["datePopup"].close();
} else if (index == 3) {
this.$refs["detailPopup"].close();
}
},
handleDateChange(date) {
this.selectedDate = date;
common_vendor.index.__f__("log", "at pages/geGuCenter/geGuCenter.vue:719", "选中的日期:", date);
},
confirmAction(index) {
if (index == 1) {
this.$refs["typePopup"].close();
} else if (index == 2) {
if (this.selectedDate) {
this.currentDate = this.selectedDate;
common_vendor.index.__f__("log", "at pages/geGuCenter/geGuCenter.vue:728", "最终确认的日期:", this.currentDate);
} else {
const now = /* @__PURE__ */ 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.marketHeatmap(this.currentDate);
this.marketStatistics();
this.marketHotspotListOverview();
this.$refs["datePopup"].close();
}
},
bkydAction(item) {
this.$refs["detailPopup"].open();
this.formattedAvg = item.formattedAvg, this.upCount = item.upCount, this.downCount = item.downCount, this.limit_up_ratio = item.limit_up_ratio, this.conceptStocksDetails(item.concept_id);
},
conceptStocksDetails(concept_id) {
common_vendor.index.__f__("log", "at pages/geGuCenter/geGuCenter.vue:754", "concept_id", concept_id);
request_api.conceptStocks(concept_id, {}).then((res) => {
if (res.data && res.data.stocks) {
let rawData = res.data.stocks;
this.conceptStocksList = rawData.sort((a, b) => {
const aValue = a.change_pct === null || a.change_pct === void 0 ? -999 : Number(a.change_pct);
const bValue = b.change_pct === null || b.change_pct === void 0 ? -999 : Number(b.change_pct);
return bValue - aValue;
});
} else {
common_vendor.index.__f__("warn", "at pages/geGuCenter/geGuCenter.vue:773", "接口返回数据格式异常", res);
}
}).catch((error) => {
});
},
// 格式化涨跌幅显示(处理正负号、保留两位小数)
formatChangePct(change_pct) {
if (typeof change_pct !== "number")
return "0.00%";
const symbol = change_pct >= 0 ? "+" : "";
return `${symbol}${change_pct.toFixed(2)}%`;
},
// 获取涨跌幅文字颜色(涨红跌绿,平盘灰色)
getChangeColor(change_pct) {
if (typeof change_pct !== "number")
return "#888888";
if (change_pct > 0)
return "#EC3440";
if (change_pct < 0)
return "#00B42A";
return "#888888";
}
}
};
if (!Array) {
const _easycom_navBar2 = common_vendor.resolveComponent("navBar");
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
const _easycom_LCCalendar22 = common_vendor.resolveComponent("LCCalendar2");
(_easycom_navBar2 + _easycom_uni_popup2 + _easycom_LCCalendar22)();
}
const _easycom_navBar = () => "../../components/navBar/navBar.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
const _easycom_LCCalendar2 = () => "../../components/LCCalendar2/LCCalendar2.js";
if (!Math) {
(_easycom_navBar + _easycom_uni_popup + _easycom_LCCalendar2)();
}
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,
d: common_vendor.o(($event) => _ctx.clickSearch()),
e: _ctx.keywords,
f: common_vendor.o(($event) => _ctx.keywords = $event.detail.value),
g: common_vendor.s("top:" + $data.navH + "px;"),
h: common_vendor.f($data.topLists, (item, index, i0) => {
return {
a: item.backIcon,
b: common_vendor.t(item.title),
c: common_vendor.t(item.value),
d: item.color,
e: index
};
}),
i: common_vendor.f($data.topLists2, (item, index, i0) => {
return {
a: common_vendor.t(item.title),
b: $data.list2Index == index ? "#BB8520" : "#070707",
c: $data.list2Index == index ? "#FFFAF1" : "#FFFFFF",
d: common_vendor.t(item.value),
e: $data.list2Index == index ? "#BB8520" : "#070707",
f: common_vendor.o(($event) => $options.handleTypeClick(index), index),
g: index,
h: `1rpx solid ${$data.list2Index == index ? "#F2C369" : "#D2D2D2"}`
};
}),
j: common_vendor.f(["股票名称", "涨跌幅", "市值", "成交额", "行业"], (item, index, i0) => {
return {
a: common_vendor.t(item),
b: index
};
}),
k: common_vendor.f($data.filteredData, (obj, j, i0) => {
return {
a: common_vendor.f($options.getTableItem(obj), (item, index, i1) => {
return common_vendor.e({
a: common_vendor.t(item[0]),
b: index == 0
}, index == 0 ? {
c: common_vendor.t(item[1])
} : {}, {
d: index,
e: index == 0 ? "#222222" : index == 1 ? item[2] === "positive" ? "#EC3440" : "#01AB5D" : "#666666"
});
}),
b: common_vendor.o(($event) => $options.itemDetails(obj)),
c: j % 2 == 0 ? "#fff" : "#FAFAFC"
};
}),
l: common_assets._imports_1$2,
m: common_vendor.o((...args) => $options.moreAction && $options.moreAction(...args)),
n: common_assets._imports_3$7,
o: common_assets._imports_4$1,
p: common_vendor.o(($event) => $options.allAction(1)),
q: common_vendor.t($data.currentDate),
r: common_assets._imports_4$1,
s: common_vendor.o(($event) => $options.allAction(2)),
t: common_assets._imports_3$7,
v: common_vendor.f($data.marketAlertsList, (item, index, i0) => {
var _a, _b, _c, _d;
return common_vendor.e({
a: common_vendor.t(item.time),
b: common_vendor.t(item.concept_name),
c: ((_a = $data.alertTypeConfig[item.alert_type]) == null ? void 0 : _a.filter) || "",
d: common_vendor.t(((_b = $data.alertTypeConfig[item.alert_type]) == null ? void 0 : _b.text) || "异动"),
e: ((_c = $data.alertTypeConfig[item.alert_type]) == null ? void 0 : _c.color) || "#FF7A45",
f: "1rpx solid " + (((_d = $data.alertTypeConfig[item.alert_type]) == null ? void 0 : _d.color) || "#FF7A45"),
g: common_vendor.t(item.formattedAvg),
h: Number(item.alpha) > 0 ? "#EC3440" : "#01AB5D",
i: common_vendor.t(item.upCount),
j: item.upCount > 0 ? "#EC3440" : "#888888",
k: common_vendor.t(item.downCount),
l: item.downCount > 0 ? "#01AB5D" : "#888888",
m: common_vendor.t(Math.round(item.final_score)),
n: item && Number(item.limit_up_ratio) > 0 && !isNaN(Number(item.limit_up_ratio))
}, item && Number(item.limit_up_ratio) > 0 && !isNaN(Number(item.limit_up_ratio)) ? {
o: common_vendor.t($options.formatLimitUpRatio(item.limit_up_ratio, 0))
} : {}, {
p: index,
q: common_vendor.o(($event) => $options.bkydAction(item), index)
});
}),
w: common_assets._imports_5$3,
x: common_vendor.s("top:" + $data.contentTop + "px;"),
y: common_vendor.o(($event) => $options.closeAction(1)),
z: common_vendor.o(($event) => $options.confirmAction(1)),
A: common_vendor.f($data.typeList, (item, index, i0) => {
return {
a: item.backIcon,
b: common_vendor.t(item.title),
c: index
};
}),
B: common_vendor.sr("typePopup", "c7f5c964-1"),
C: common_vendor.p({
type: "bottom",
safeArea: false
}),
D: common_vendor.o(($event) => $options.closeAction(2)),
E: common_vendor.o(($event) => $options.confirmAction(2)),
F: common_vendor.o($options.handleDateChange),
G: common_vendor.sr("datePopup", "c7f5c964-2"),
H: common_vendor.p({
type: "bottom",
safeArea: false
}),
I: common_assets._imports_8,
J: common_vendor.o(($event) => $options.closeAction(3)),
K: common_vendor.t($data.formattedAvg),
L: Number($data.formattedAvg) > 0 ? "#EC3440" : "#01AB5D",
M: common_vendor.t($data.upCount),
N: $data.upCount > 0 ? "#EC3440" : "#888888",
O: common_vendor.t($data.downCount),
P: $data.downCount > 0 ? "#01AB5D" : "#888888",
Q: common_vendor.t($options.formatLimitUpRatio($data.limit_up_ratio, 0)),
R: common_vendor.f($data.conceptStocksList, (item, index, i0) => {
return {
a: common_vendor.t(item.name),
b: common_vendor.t(item.code),
c: common_vendor.t($options.formatChangePct(item.change_pct)),
d: $options.getChangeColor(item.change_pct),
e: index,
f: index % 2 == 0 ? "#fff" : "#FAFAFC"
};
}),
S: common_vendor.sr("detailPopup", "c7f5c964-4"),
T: common_vendor.p({
type: "bottom",
safeArea: false
})
};
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/geGuCenter/geGuCenter.js.map