submit
parent
4d8b4717f7
commit
3529fb5b64
@ -0,0 +1,43 @@
|
|||||||
|
// storage.js
|
||||||
|
|
||||||
|
class StorageService {
|
||||||
|
constructor(storage) {
|
||||||
|
this.storage = storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
setItem(key, value, expire = null) {
|
||||||
|
const obj = {
|
||||||
|
data: value,
|
||||||
|
};
|
||||||
|
if (expire) {
|
||||||
|
const expireTime = new Date().getTime() + expire * 1000;
|
||||||
|
obj.expire = expireTime;
|
||||||
|
}
|
||||||
|
this.storage.setItem(key, JSON.stringify(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
getItem(key) {
|
||||||
|
const itemStr = this.storage.getItem(key);
|
||||||
|
if (!itemStr) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const item = JSON.parse(itemStr);
|
||||||
|
if (item.expire && new Date().getTime() > item.expire) {
|
||||||
|
this.storage.removeItem(key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return item.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeItem(key) {
|
||||||
|
this.storage.removeItem(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
this.storage.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const localStorageService = new StorageService(window.localStorage);
|
||||||
|
|
||||||
|
export default localStorageService;
|
@ -0,0 +1,11 @@
|
|||||||
|
<script setup>
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
upload-id-card
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
|
||||||
|
</style>
|
Loading…
Reference in New Issue