修复一些缺陷,更换tabbar素材

This commit is contained in:
hejinfu1026
2021-11-15 10:16:11 +08:00
parent 08ad262a88
commit 6c30520d5f
19 changed files with 284 additions and 137 deletions

View File

@@ -1,3 +1,13 @@
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import { EXPIRE } from '../config/app';
class Cache {
@@ -7,6 +17,7 @@ class Cache {
this.cacheGetHandler = uni.getStorageSync;
this.cacheClearHandler = uni.removeStorageSync;
this.cacheExpire = '_expire_2019_12_17_18_44';
this.name = 'storage';
}
/**
@@ -18,7 +29,7 @@ class Cache {
}
/**
* 字符串转时间戳
* 日期字符串转时间戳
* @param {Object} expiresTime
*/
strTotime(expiresTime){
@@ -27,17 +38,64 @@ class Cache {
return Math.round(new Date(expires_time).getTime() / 1000);
}
setExpireCaheTag(key, expire) {
expire = expire !== undefined ? expire : EXPIRE;
if (typeof expire === 'number') {
let tag = this.cacheGetHandler(this.cacheExpire), newTag = [],newKeys = [];
if (typeof tag === 'object' && tag.length) {
newTag = tag.map(item => {
newKeys.push(item.key);
if (item.key === key) {
item.expire = expire === 0 ? 0 : this.time() + expire;
}
return item;
});
}
if (!newKeys.length || newKeys.indexOf(key) === -1) {
newTag.push({
key: key,
expire: expire === 0 ? 0 : this.time() + expire
});
}
this.cacheSetHandler(this.cacheExpire, newTag);
}
}
/**
* 设置过期时间缓存
* @param {Object} key
* @param {Object} expire
* @param {Object} name key
* @param {Object} value value
* @param {Object} expire 过期时间
* @param {Object} startTime 记录何时将值存入缓存,毫秒级
*/
setExpireCahe(key,expire)
{
expire = expire !== undefined ? expire : EXPIRE;
if (expire) {
this.cacheSetHandler(key + this.cacheExpire,this.time() + expire)
}
setItem(params){
let obj = {
name:'',
value:'',
expires:"",
startTime:new Date().getTime()
}
let options = {};
//将obj和传进来的params合并
Object.assign(options,obj,params);
if(options.expires){
//如果options.expires设置了的话
//以options.name为keyoptions为值放进去
// localStorage.setItem(options.name,JSON.stringify(options));
uni.setStorageSync(options.name,JSON.stringify(options));
}else{
//如果options.expires没有设置就判断一下value的类型
let type = Object.prototype.toString.call(options.value);
//如果value是对象或者数组对象的类型就先用JSON.stringify转一下再存进去
if(Object.prototype.toString.call(options.value) == '[object Object]'){
options.value = JSON.stringify(options.value);
}
if(Object.prototype.toString.call(options.value) == '[object Array]'){
options.value = JSON.stringify(options.value);
}
// localStorage.setItem(options.name,options.value);
uni.setStorageSync(options.name,options.value);
}
}
/**
@@ -76,8 +134,8 @@ class Cache {
if(typeof data === 'object')
data = JSON.stringify(data);
try{
this.setExpireCahe(key,expire);
return this.cacheSetHandler(key,data);
this.setExpireCaheTag(key,expire);
return this.cacheSetHandler(key,data);
}catch(e){
return false;
}
@@ -150,6 +208,39 @@ class Cache {
// })
// }
}
/**
* 获取缓存,调用后无需转换数据类型
* @param {Object} key
*/
getItem(name){
// let item = localStorage.getItem(name);
let item = uni.getStorageSync(name);
//先将拿到的试着进行json转为对象的形式
try{
item = JSON.parse(item);
}catch(error){
//如果不行就不是json的字符串就直接返回
item = item;
}
//如果有startTime的值说明设置了失效时间
if(item.startTime){
let date = new Date().getTime();
//何时将值取出减去刚存入的时间与item.expires比较如果大于就是过期了如果小于或等于就还没过期
if(date - item.startTime > item.expires){
//缓存过期清除缓存返回false
// localStorage.removeItem(name);
uni.removeStorageSync(name);
return false;
}else{
//缓存未过期,返回值
return item.value;
}
}else{
//如果没有设置失效时间,直接返回值
return item;
}
}
}