增加触摸事件处理,支持长按切换分类显示,优化移动端用户体验

This commit is contained in:
hi2hi 2025-03-25 16:34:59 +08:00
parent bc50b78135
commit d7d4112e70

View File

@ -82,6 +82,9 @@
'--cate-color': cateItem.color, '--cate-color': cateItem.color,
}" }"
@click="toggleShowCate(cateItem.id)" @click="toggleShowCate(cateItem.id)"
@touchstart="handleTouchStart(cateItem.id)"
@touchend="handleTouchEnd(cateItem.id)"
@touchmove="handleTouchMove(cateItem.id)"
> >
<span class="cate-legend" /> <span class="cate-legend" />
<span <span
@ -169,8 +172,8 @@ const minutes = [{
const refreshData = ref(true); const refreshData = ref(true);
const peakShaving = ref(false); const peakShaving = ref(false);
const showCates = ref({}); const showCates = ref({});
const monitorData = ref([]); const monitorData = ref([]);
const longPressTimer = ref(null);
const now = ref(Date.now()); const now = ref(Date.now());
const accpetShowTime = computed(() => now.value - (minute.value * 60 * 1000)); const accpetShowTime = computed(() => now.value - (minute.value * 60 * 1000));
@ -317,9 +320,32 @@ function toggleMinute(value) {
} }
function toggleShowCate(id) { function toggleShowCate(id) {
if (window.innerWidth < 768) {
return;
}
showCates.value[id] = !showCates.value[id]; showCates.value[id] = !showCates.value[id];
} }
function handleTouchStart(id) {
longPressTimer.value = setTimeout(() => {
showCates.value[id] = !showCates.value[id];
}, 500);
}
function handleTouchEnd() {
if (longPressTimer.value) {
clearTimeout(longPressTimer.value);
longPressTimer.value = null;
}
}
function handleTouchMove() {
if (longPressTimer.value) {
clearTimeout(longPressTimer.value);
longPressTimer.value = null;
}
}
async function loadMonitor() { async function loadMonitor() {
await request({ await request({
url: ( url: (
@ -548,6 +574,10 @@ onUnmounted(() => {
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
@media screen and (max-width: 768px) {
cursor: default;
}
.cate-legend { .cate-legend {
width: 0.5em; width: 0.5em;
height: 0.5em; height: 0.5em;