Files
JayuCloud/WeChatProgram/admin/utils/device.js
T

29 lines
974 B
JavaScript
Raw Normal View History

const { STORAGE_KEYS, getStorage, setStorage } = require('./storage')
2026-05-23 18:45:41 +08:00
/**
* Purpose: createDeviceId supports device.js by holding or executing the create device id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function createDeviceId() {
const randomText = Math.random().toString(36).slice(2, 10)
return `admin-mini-device-${Date.now()}-${randomText}`
}
2026-05-23 18:45:41 +08:00
/**
* Purpose: getDeviceId supports device.js by holding or executing the get device id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function getDeviceId() {
let value = getStorage(STORAGE_KEYS.DEVICE_ID, '')
if (value) {
return value
}
value = createDeviceId()
setStorage(STORAGE_KEYS.DEVICE_ID, value)
return value
}
module.exports = {
getDeviceId
}