util.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import $C from './config.js'
  2. const {
  3. brandId,
  4. branchId
  5. } = uni.getStorageSync('brandInfo')
  6. export default {
  7. // 获取存储列表数据
  8. getStorage(key) {
  9. // let data = null;
  10. // // #ifdef H5
  11. // if($C.env === 'dev'){
  12. // data = window.sessionStorage.getItem(key)
  13. // } else {
  14. // data = uni.getStorageSync(key)
  15. // }
  16. // // #endif
  17. // // #ifndef H5
  18. // data = uni.getStorageSync(key)
  19. // // #endif
  20. return uni.getStorageSync(key)
  21. },
  22. // 设置存储
  23. setStorage(key, data) {
  24. // // #ifdef H5
  25. // if($C.env === 'dev'){
  26. // return window.sessionStorage.setItem(key,data)
  27. // } else {
  28. // return uni.setStorageSync(key,data)
  29. // }
  30. // // #endif
  31. // // #ifndef H5
  32. return uni.setStorageSync(key, data)
  33. // // #endif
  34. },
  35. // 删除存储
  36. removeStorage(key) {
  37. // // #ifdef H5
  38. // if($C.env === 'dev'){
  39. // return window.sessionStorage.removeItem(key);
  40. // } else {
  41. // return uni.removeStorageSync(key)
  42. // }
  43. // // #endif
  44. // // #ifndef H5
  45. return uni.removeStorageSync(key)
  46. // // #endif
  47. },
  48. setUserInfo(userInfoData) {
  49. // console.log(userInfoData);
  50. var userInfoStr = uni.setStorageSync("userInfo", JSON.stringify(userInfoData))
  51. console.log(userInfoStr);
  52. },
  53. getUserInfo() {
  54. var userInfoData = uni.getStorageSync(`userInfo_${brandId}`);
  55. return userInfoData;
  56. },
  57. getConfigName(data, key, value, nameKey) {
  58. if (Array.isArray(data)) {
  59. let result = data.find(item => item[key] == value)
  60. return result && result[nameKey] || ''
  61. }
  62. },
  63. getDataName(key) {
  64. console.log(9000, key, `${key}_${brandId}_${branchId}`)
  65. return `${key}_${brandId}_${branchId}`
  66. }
  67. }