Browse Source

分时数据对接

lihuilin/feature-20251024095243-我的
hongxilin 4 weeks ago
parent
commit
91b162dd01
  1. 87
      pages/marketSituation/marketCondition.vue

87
pages/marketSituation/marketCondition.vue

@ -963,6 +963,7 @@ const drawChart = () => {
return; return;
} }
const data = klineTab.value == 1 ? timeData.value : klineData.value; const data = klineTab.value == 1 ? timeData.value : klineData.value;
console.log("data", data);
chartRange.value = []; chartRange.value = [];
// //
// HCharts.setCanvasColor(ctx.value, width, height, CANVAS_BACKGROUND_COLOR); // HCharts.setCanvasColor(ctx.value, width, height, CANVAS_BACKGROUND_COLOR);
@ -1632,7 +1633,6 @@ const findJsonPacket = (message, command) => {
} }
} }
} }
for (let i = message.indexOf(command); i >= 0; --i) { for (let i = message.indexOf(command); i >= 0; --i) {
if (message[i] == "}" || i == jsonStartIndex) { if (message[i] == "}" || i == jsonStartIndex) {
jsonEndCount++; jsonEndCount++;
@ -1647,8 +1647,45 @@ const findJsonPacket = (message, command) => {
if (jsonStartIndex >= jsonEndIndex) { if (jsonStartIndex >= jsonEndIndex) {
return { error: true }; return { error: true };
} }
return { json: JSON.parse(message.substring(jsonStartIndex, jsonEndIndex + 1)) }; return { json: JSON.parse(message.substring(jsonStartIndex, jsonEndIndex + 1)) };
}; };
// timeData
const generateNextTime = () => {
if (timeData.value.length === 0) {
return "09:30"; //
}
const lastTime = timeData.value[timeData.value.length - 1].time;
if (!lastTime) {
return "09:30";
}
// "HH:MM"
const [hours, minutes] = lastTime.split(":").map(Number);
//
let nextMinutes = minutes + 1;
let nextHours = hours;
//
if (nextMinutes >= 60) {
nextMinutes = 0;
nextHours += 1;
}
// 24
if (nextHours >= 24) {
nextHours = 0;
}
// "HH:MM"
const formattedHours = nextHours.toString().padStart(2, "0");
const formattedMinutes = nextMinutes.toString().padStart(2, "0");
return `${formattedHours}:${formattedMinutes}`;
};
// TCP // TCP
const parseStockData = (message) => { const parseStockData = (message) => {
try { try {
@ -1662,7 +1699,49 @@ const parseStockData = (message) => {
console.log("服务器命令列表,不予处理"); console.log("服务器命令列表,不予处理");
return; return;
} }
if ((typeof message === "string" && message.includes("init_real_data_start")) || isMorePacket.init_real_time) {
if (message.includes("real_time")) {
let startIndex = 0;
let endIndex = message.length;
for (let i = 0; i < message.length - 1; ++i) {
if (message[i] == "{") {
startIndex = i;
break;
}
}
for (let i = message.length - 1; i >= 0; --i) {
if (message[i] == "}") {
endIndex = i;
break;
}
}
parsedMessage = JSON.parse(message.substring(startIndex, endIndex + 1));
console.log("实时数据解析", parsedMessage);
//
timeData.value.push({
time: generateNextTime(),
price: parsedMessage.current_price,
volume: parsedMessage.volume,
amount: parsedMessage.amount,
});
//
stockInformation.value.currentPrice = parsedMessage.current_price;
stockInformation.value.openPrice = parsedMessage.open_price;
stockInformation.value.closePrice = parsedMessage.close_price;
stockInformation.value.highPrice = parsedMessage.high_price;
stockInformation.value.lowPrice = parsedMessage.low_price;
stockInformation.value.volume = parsedMessage.volume;
stockInformation.value.amount = parsedMessage.amount;
stockInformation.value.turnoverRatio = parsedMessage.turnover_ratio;
stockInformation.value.marketValue = parsedMessage.total_market_value;
stockInformation.value.currentValue = stockInformation.value.currentPrice - stockInformation.value.lastDayStockClosePrice;
stockInformation.value.currentRatio = ((stockInformation.value.currentPrice - stockInformation.value.lastDayStockClosePrice) / stockInformation.value.lastDayStockClosePrice) * 100;
console.log("重绘画面");
drawChart();
if (timeData.value.length >= 240) {
sendTcpMessage("stop_real_time");
}
return;
} else if ((typeof message === "string" && message.includes("init_real_data_start")) || isMorePacket.init_real_time) {
if (typeof message === "string" && message.includes("init_real_data_start")) { if (typeof message === "string" && message.includes("init_real_data_start")) {
console.log("开始接受分包数据"); console.log("开始接受分包数据");
receivedMessage = ""; receivedMessage = "";
@ -1948,7 +2027,9 @@ onMounted(async () => {
console.warn("没有时间数据,跳过股票信息计算"); console.warn("没有时间数据,跳过股票信息计算");
} }
await nextTick(); await nextTick();
initCanvas();
setTimeout(() => {
initCanvas();
}, 100);
console.log("所有初始化步骤完成"); console.log("所有初始化步骤完成");
} catch (error) { } catch (error) {
console.error("初始化过程中出现错误:", error); console.error("初始化过程中出现错误:", error);

Loading…
Cancel
Save