You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spring-boot-online-exam/frontend/src/utils/device.js

40 lines
884 B

import enquireJs from 'enquire.js'
// 定义设备类型
export const DEVICE_TYPE = {
DESKTOP: 'desktop',
TABLET: 'tablet',
MOBILE: 'mobile'
}
// 设备查询函数
export const deviceEnquire = function (callback) {
// 匹配桌面设备
const matchDesktop = {
match: () => {
callback && callback(DEVICE_TYPE.DESKTOP)
}
}
// 匹配平板设备
const matchLablet = {
match: () => {
callback && callback(DEVICE_TYPE.TABLET)
}
}
// 匹配手机设备
const matchMobile = {
match: () => {
callback && callback(DEVICE_TYPE.MOBILE)
}
}
// 注册设备查询
// screen and (max-width: 1087.99px)
enquireJs
.register('screen and (max-width: 576px)', matchMobile)
.register('screen and (min-width: 576px) and (max-width: 1199px)', matchLablet)
.register('screen and (min-width: 1200px)', matchDesktop)
}