2025-01-15 20:24:13 +08:00
|
|
|
|
import { computed } from "vue";
|
|
|
|
|
|
import { useWindowSize } from "@vueuse/core";
|
|
|
|
|
|
|
2025-05-18 12:22:07 +08:00
|
|
|
|
interface DeviceSize {
|
|
|
|
|
|
isPc: ComputedRef<boolean>;
|
|
|
|
|
|
isPad: ComputedRef<boolean>;
|
|
|
|
|
|
isMobile: ComputedRef<boolean>;
|
|
|
|
|
|
}
|
2025-01-15 20:24:13 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 小于 768px:适配移动设备(如手机)。
|
|
|
|
|
|
* 768px - 1024px:适配平板设备。
|
|
|
|
|
|
* 大于 1024px:适配桌面设备。
|
|
|
|
|
|
* @returns PC窗口isPc, 平板窗口isPad, 移动端窗口isMobile
|
|
|
|
|
|
*/
|
2025-05-18 12:22:07 +08:00
|
|
|
|
export const useDevicesSize = (): DeviceSize => {
|
2025-01-15 20:24:13 +08:00
|
|
|
|
const { width } = useWindowSize();
|
|
|
|
|
|
const isPc = computed(() => width.value > 1024);
|
|
|
|
|
|
const isPad = computed(() => width.value > 768 && width.value <= 1024);
|
|
|
|
|
|
const isMobile = computed(() => width.value <= 768);
|
|
|
|
|
|
return { isPc, isPad, isMobile };
|
|
|
|
|
|
};
|