fix: 修正拖曳事件僅在目標元素上觸發,並確保左鍵拖曳有效性
| 確保即時數據為陣列,避免反轉時出現錯誤
This commit is contained in:
parent
bb549311df
commit
d01d3e7581
@ -4,13 +4,16 @@ const moveModal = (elmnt) => {
|
|||||||
pos2 = 0,
|
pos2 = 0,
|
||||||
pos3 = 0,
|
pos3 = 0,
|
||||||
pos4 = 0;
|
pos4 = 0;
|
||||||
document.body.addEventListener("mousedown", dragMouseDown, {
|
// 只在目標元素上監聽 mousedown,避免全域攔截
|
||||||
|
elmnt.addEventListener("mousedown", dragMouseDown, {
|
||||||
passive: false,
|
passive: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
function dragMouseDown(e) {
|
function dragMouseDown(e) {
|
||||||
console.log("dragMouseDown", e);
|
console.log("dragMouseDown", e);
|
||||||
e = e || window.event;
|
e = e || window.event;
|
||||||
|
// 僅當左鍵拖曳才阻止預設(避免影響下拉選單等)
|
||||||
|
if (e.button !== 0) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// get the mouse cursor position at startup:
|
// get the mouse cursor position at startup:
|
||||||
pos3 = e.clientX;
|
pos3 = e.clientX;
|
||||||
|
@ -56,7 +56,7 @@ const getData = async () => {
|
|||||||
const getRealTime = async () => {
|
const getRealTime = async () => {
|
||||||
if (store.selectedBuilding.building_guid) {
|
if (store.selectedBuilding.building_guid) {
|
||||||
const res = await getRealTimeDemand(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();
|
updateChart();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user