Init project
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { trim, isType } from "@/utils";
|
||||
|
||||
const doc = null;
|
||||
// const doc = window.document;
|
||||
|
||||
function get(key) {
|
||||
if (!key || !_has(key)) {
|
||||
return null;
|
||||
}
|
||||
return uni.getStorageSync(key)
|
||||
}
|
||||
|
||||
function all() {
|
||||
return uni.getStorageInfoSync()
|
||||
}
|
||||
|
||||
function set(key, data, time) {
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
uni.setStorageSync(key, data)
|
||||
}
|
||||
|
||||
function remove(key) {
|
||||
if (!key || !_has(key)) {
|
||||
return;
|
||||
}
|
||||
uni.removeStorageSync(key)
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
// uni.clearStorage()
|
||||
const res = uni.getStorageInfoSync();
|
||||
res.keys.map((item) => {
|
||||
//不要清除spread和redirect
|
||||
if (item == 'redirect' || item == 'spread') {
|
||||
return
|
||||
}
|
||||
remove(item)
|
||||
})
|
||||
console.log(res)
|
||||
}
|
||||
|
||||
function _has(key) {
|
||||
if (!key) {
|
||||
return
|
||||
}
|
||||
let value = uni.getStorageSync(key)
|
||||
if (value) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export default {
|
||||
get,
|
||||
all,
|
||||
set,
|
||||
remove,
|
||||
clearAll,
|
||||
has: _has
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import cookie from "./cookie";
|
||||
import localStorage from "./localStorage";
|
||||
|
||||
export default {
|
||||
cookie,
|
||||
localStorage
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
function localStorage() {
|
||||
return window.localStorage;
|
||||
}
|
||||
|
||||
function get(key) {
|
||||
return JSON.parse(localStorage().getItem(key));
|
||||
}
|
||||
|
||||
function set(key, data) {
|
||||
return localStorage().setItem(key, JSON.stringify(data));
|
||||
}
|
||||
|
||||
function all() {
|
||||
const data = {};
|
||||
for (var i = localStorage().length - 1; i >= 0; i--) {
|
||||
var key = localStorage().key(i);
|
||||
data[key] = get(key);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function remove(key) {
|
||||
return localStorage().removeItem(key);
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
return localStorage().clear();
|
||||
}
|
||||
|
||||
function has(key) {
|
||||
return localStorage().getItem(key) !== null;
|
||||
}
|
||||
|
||||
export default {
|
||||
get,
|
||||
set,
|
||||
all,
|
||||
remove,
|
||||
clearAll,
|
||||
has
|
||||
};
|
||||
Reference in New Issue
Block a user