style: ui style

This commit is contained in:
jialin
2024-07-02 15:03:38 +08:00
parent 6989345088
commit 49efbd1a7f
38 changed files with 336 additions and 135 deletions
+25
View File
@@ -0,0 +1,25 @@
import localStore from './store';
const store = localStore.createInstance({ name: '_xWXJKJ_S1Sna_' });
const rememberMe = (key: string, data: any) => {
if (store) {
store.setItem(key, data);
}
};
const getRememberMe = (key: string) => {
if (store) {
return store.getItem(key);
}
};
const removeRememberMe = (key: string) => {
if (store) {
store.removeItem(key);
}
};
export { getRememberMe, rememberMe, removeRememberMe };
export default store;
+51
View File
@@ -0,0 +1,51 @@
import dayjs from 'dayjs';
import localForage from 'localforage';
import { get } from 'lodash';
class Localestore extends Object.getPrototypeOf(localForage).constructor {
constructor() {
super();
this.state = {};
}
public async removeValue(key: string) {
return localForage.removeItem(key);
}
public async setValue(
key: string,
value: any,
callback?: (args?: any) => void,
expire?: number
) {
if (!expire) {
return localForage.setItem(key, { value }, callback);
}
return localForage.setItem(
key,
{
value,
expire: {
expire,
createTime: dayjs().valueOf(),
expiration: dayjs().add(expire, 'day').valueOf()
}
},
callback
);
}
public async getValue(key: string, callback?: (args?: any) => void) {
const storeValue = await localForage.getItem(key, callback);
const expire = get(storeValue, 'expire');
if (!expire) return storeValue;
const expiration = get(expire, 'expiration');
return {
value: get(storeValue, 'value'),
isExpiration: dayjs().isAfter(expiration)
};
}
}
export default new Localestore();