util.ts 1.1 KB

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