feat:添加扫码器/手机设备判断
parent
fb08eed1d4
commit
60c45a2af0
@ -0,0 +1,46 @@
|
|||||||
|
const TerminalTypeKey = 'App-Terminal-Type'
|
||||||
|
|
||||||
|
export const TERMINAL_TYPE_MOBILE = 1
|
||||||
|
export const TERMINAL_TYPE_SCANNER = 2
|
||||||
|
|
||||||
|
function normalizeTerminalType(value: unknown) {
|
||||||
|
return Number(value) === TERMINAL_TYPE_SCANNER ? TERMINAL_TYPE_SCANNER : TERMINAL_TYPE_MOBILE
|
||||||
|
}
|
||||||
|
|
||||||
|
export function detectTerminalType() {
|
||||||
|
const systemInfo = uni.getSystemInfoSync()
|
||||||
|
const width = Number(systemInfo.windowWidth || systemInfo.screenWidth || 0)
|
||||||
|
const height = Number(systemInfo.windowHeight || systemInfo.screenHeight || 0)
|
||||||
|
|
||||||
|
if (width === 480 && height === 800) {
|
||||||
|
return TERMINAL_TYPE_SCANNER
|
||||||
|
}
|
||||||
|
|
||||||
|
return TERMINAL_TYPE_MOBILE
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTerminalType() {
|
||||||
|
const storedValue = uni.getStorageSync(TerminalTypeKey)
|
||||||
|
if (storedValue === '' || storedValue === null || typeof storedValue === 'undefined') {
|
||||||
|
return TERMINAL_TYPE_MOBILE
|
||||||
|
}
|
||||||
|
return normalizeTerminalType(storedValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setTerminalType(value: unknown) {
|
||||||
|
const terminalType = normalizeTerminalType(value)
|
||||||
|
uni.setStorageSync(TerminalTypeKey, terminalType)
|
||||||
|
return terminalType
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeTerminalType() {
|
||||||
|
uni.removeStorageSync(TerminalTypeKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initializeTerminalType() {
|
||||||
|
const storedValue = uni.getStorageSync(TerminalTypeKey)
|
||||||
|
if (storedValue === '' || storedValue === null || typeof storedValue === 'undefined') {
|
||||||
|
return setTerminalType(detectTerminalType())
|
||||||
|
}
|
||||||
|
return normalizeTerminalType(storedValue)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue