util.ts 756 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { log } from "./log"
  2. export class util {
  3. /**
  4. * 获取本地数据
  5. */
  6. public static getStorage(key:string){
  7. let d = uni.getStorageSync(key)
  8. if(util.isNull(d)){
  9. return null
  10. }
  11. return d
  12. }
  13. /**
  14. * 设置本地数据
  15. */
  16. public static setStorage(key:string,value:string){
  17. uni.setStorageSync(key,value)
  18. }
  19. /**
  20. * 清除本地key数据
  21. */
  22. public static clearStorageForKey(key:string){
  23. let d = util.getStorage(key)
  24. if(util.isNull(d)){
  25. log.Error(`${key} is null!`);
  26. }else{
  27. util.setStorage(key,null)
  28. }
  29. }
  30. /**
  31. * 清除本地数据
  32. */
  33. public static clearAllStorage(){
  34. uni.clearStorageSync()
  35. }
  36. public static isNull(v:any){
  37. if(v==null||v==undefined||v==""){
  38. return true
  39. }
  40. return false
  41. }
  42. }