Commit 751e48b1 by Tianqing Liu

Merge remote-tracking branch 'origin/app' into app

2 parents b8833ab1 5e10a594
<template> <template>
<div> <div class="heat-map-container">
<div class="heat-map" style="background-color: #fff"> <div class="heat-map" style="background-color: #fff">
<div class="canvas"> <div class="canvas">
<img <img
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
class="editFloorimg" class="editFloorimg"
id="editFloorimg" id="editFloorimg"
style="width: 100%" style="width: 100%"
@load="handleLoad"
/> />
<canvas class="canvas-position" id="canvas-position"></canvas> <canvas class="canvas-position" id="canvas-position"></canvas>
</div> </div>
...@@ -58,6 +59,22 @@ const getFloorImage = async () => { ...@@ -58,6 +59,22 @@ const getFloorImage = async () => {
return ""; return "";
} }
}; };
const handleLoad = () => {
const domHeight =
document.querySelector(".heat-map-container")?.clientHeight || 0;
uni.postMessage({
data: {
height: domHeight,
type: "setHeight",
},
});
window.postMessage({
data: {
height: domHeight,
type: "setHeight",
},
});
};
/************** 通道数据相关 **************/ /************** 通道数据相关 **************/
const channelList = ref([]); // 渠道列表 const channelList = ref([]); // 渠道列表
...@@ -78,6 +95,7 @@ const getChannelList = async (mallId) => { ...@@ -78,6 +95,7 @@ const getChannelList = async (mallId) => {
}; };
// 获取区域数据 // 获取区域数据
const gateData = ref([]); const gateData = ref([]);
const gateDataMap = ref({}); // 用于存储区域数据的映射
const getGateStatistics = async () => { const getGateStatistics = async () => {
try { try {
const params = { const params = {
...@@ -88,10 +106,16 @@ const getGateStatistics = async () => { ...@@ -88,10 +106,16 @@ const getGateStatistics = async () => {
const { data } = await heatmap.getAreaGateStatisticsApi(params); const { data } = await heatmap.getAreaGateStatisticsApi(params);
if (data.code === 200) { if (data.code === 200) {
gateData.value = data.data || []; gateData.value = data.data || [];
gateDataMap.value = {};
gateData.value.forEach((item) => {
gateDataMap.value[item.gateId] = item;
});
processGateLegend(); processGateLegend();
if (gateData.value.length > 0) { if (gateData.value.length > 0) {
drawAreaCanvas(); drawAreaCanvas();
} }
const domHeight = document.documentElement.clientHeight;
console.log(domHeight);
} }
} catch (error) { } catch (error) {
console.error("获取区域数据失败:", error); console.error("获取区域数据失败:", error);
...@@ -185,14 +209,43 @@ function drawAreaCanvas() { ...@@ -185,14 +209,43 @@ function drawAreaCanvas() {
let selectedArea = areas.value.find((area) => { let selectedArea = areas.value.find((area) => {
return ctx.isPointInPath(area.path, x, y); return ctx.isPointInPath(area.path, x, y);
}); });
uni.postMessage( const item = gateDataMap.value[selectedArea?.gateId];
JSON.parse( if (item) {
JSON.stringify({ const params = {
type: "areaClick", gateId: selectedArea?.gateId,
data: selectedArea ? selectedArea : null, gateName: item.gateName || "",
}) indicatorKey: indicatorKey.value,
) val: item[indicatorKey.value] || 0,
); };
if (
[
"totalResidenceTime",
"avgResidenceTime",
"validDwellTime",
"avgValidDwellTime",
].includes(indicatorKey.value)
) {
params.val = getTimeMin(params.val);
}
window.postMessage(
JSON.parse(
JSON.stringify({
type: "areaClick",
data: params,
})
)
);
console.log(params);
uni.postMessage(
JSON.parse(
JSON.stringify({
type: "areaClick",
data: params,
})
)
);
}
}; };
} }
...@@ -314,6 +367,19 @@ watch( ...@@ -314,6 +367,19 @@ watch(
}, },
{ immediate: true } { immediate: true }
); );
function getTimeMin(seconds) {
if (isNaN(seconds)) return seconds;
return (
numFormat(parseInt(seconds / 3600)) +
":" +
numFormat(parseInt((seconds % 3600) / 60)) +
":00"
);
}
function numFormat(val) {
return val > 9 ? val : "0" + val;
}
</script> </script>
<style> <style>
.canvas { .canvas {
...@@ -329,9 +395,8 @@ watch( ...@@ -329,9 +395,8 @@ watch(
z-index: 1; z-index: 1;
} }
.color-legend { .color-legend {
width: auto; height: 70px;
height: auto; margin-top: 30px;
margin-top: 20px;
} }
.color-box { .color-box {
float: left; float: left;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
class="editFloorimg" class="editFloorimg"
id="editFloorimg" id="editFloorimg"
style="width: 100%" style="width: 100%"
@load="handleLoad"
/> />
<div class="canvas-position" id="canvas-position"></div> <div class="canvas-position" id="canvas-position"></div>
</div> </div>
...@@ -93,6 +94,7 @@ const getHeatMapData = async (params) => { ...@@ -93,6 +94,7 @@ const getHeatMapData = async (params) => {
dealHeatData(); dealHeatData();
}); });
} else { } else {
Toast.fail("获取热力图数据失败");
} }
} catch (error) { } catch (error) {
console.error("Error fetching heat map data:", error); console.error("Error fetching heat map data:", error);
...@@ -114,6 +116,21 @@ const getFloorImage = async () => { ...@@ -114,6 +116,21 @@ const getFloorImage = async () => {
return ""; return "";
} }
}; };
const handleLoad = () => {
const domHeight = document.querySelector(".heat-map")?.clientHeight || 0;
uni.postMessage({
data: {
height: domHeight + 60,
type: "setHeight",
},
});
window.postMessage({
data: {
height: domHeight + 60,
type: "setHeight",
},
});
};
/************** 热力图相关 **************/ /************** 热力图相关 **************/
const heatInstance = ref(null); const heatInstance = ref(null);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!