fix: 修正拖曳事件僅在目標元素上觸發,並確保左鍵拖曳有效性

| 確保即時數據為陣列,避免反轉時出現錯誤
This commit is contained in:
koko 2025-09-26 13:44:45 +08:00
parent bb549311df
commit d01d3e7581
2 changed files with 5 additions and 2 deletions

View File

@ -4,13 +4,16 @@ const moveModal = (elmnt) => {
pos2 = 0,
pos3 = 0,
pos4 = 0;
document.body.addEventListener("mousedown", dragMouseDown, {
// 只在目標元素上監聽 mousedown避免全域攔截
elmnt.addEventListener("mousedown", dragMouseDown, {
passive: false,
});
function dragMouseDown(e) {
console.log("dragMouseDown", e);
e = e || window.event;
// 僅當左鍵拖曳才阻止預設(避免影響下拉選單等)
if (e.button !== 0) return;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;

View File

@ -56,7 +56,7 @@ const getData = async () => {
const getRealTime = async () => {
if (store.selectedBuilding.building_guid) {
const res = await getRealTimeDemand(store.selectedBuilding.building_guid);
realTimeDemand.value = res.data.reverse();
realTimeDemand.value = Array.isArray(res.data) ? res.data.reverse() : [];
updateChart();
}
};