Files

59 lines
914 B
JavaScript
Raw Normal View History

2022-07-19 23:21:37 +08:00
import { trim, isType } from '@/utils'
2020-03-15 13:59:43 +08:00
2022-07-19 23:21:37 +08:00
const doc = null
const CACHE_KEY = 'clear_0.0.1'
2020-03-15 13:59:43 +08:00
// const doc = window.document;
function get(key) {
2020-03-18 19:01:12 +08:00
return uni.getStorageSync(key)
2020-03-15 13:59:43 +08:00
}
function all() {
2020-03-18 19:01:12 +08:00
return uni.getStorageInfoSync()
2020-03-15 13:59:43 +08:00
}
function set(key, data, time) {
if (!key) {
2022-07-19 23:21:37 +08:00
return
2020-03-15 13:59:43 +08:00
}
2020-03-18 19:01:12 +08:00
uni.setStorageSync(key, data)
2020-03-15 13:59:43 +08:00
}
function remove(key) {
if (!key || !_has(key)) {
2022-07-19 23:21:37 +08:00
return
2020-03-15 13:59:43 +08:00
}
2020-03-18 19:01:12 +08:00
uni.removeStorageSync(key)
2020-03-15 13:59:43 +08:00
}
function clearAll() {
2022-07-19 23:21:37 +08:00
const res = uni.getStorageInfoSync()
res.keys.map(item => {
if (item == 'redirect' || item == 'spread' || item == CACHE_KEY) {
return
}
remove(item)
})
2020-03-15 13:59:43 +08:00
}
function _has(key) {
if (!key) {
return
}
2020-03-18 19:01:12 +08:00
let value = uni.getStorageSync(key)
2020-03-15 13:59:43 +08:00
if (value) {
return true
}
return false
}
export default {
get,
all,
set,
remove,
clearAll,
2022-07-19 23:21:37 +08:00
has: _has,
CACHE_KEY,
}