index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // 应用设置存储key值
  2. export const _AppConfigKey = 'APP_GLOBAL_CONFIGS';
  3. export const _AppMockJsonKey = 'APP_GLOBAL_MOCK_JSON';
  4. // 默认的应用设置
  5. export const DefaultAppConfigs = {
  6. loveConfig: {},
  7. imagesConfig: {},
  8. authorConfig: {},
  9. appConfig: {},
  10. pluginConfig: {},
  11. pageConfig: {}
  12. }
  13. /**
  14. * 获取应用设置
  15. */
  16. export const getAppConfigs = () => {
  17. let configs = uni.getStorageSync(_AppConfigKey)
  18. if (configs) return JSON.parse(configs)
  19. uni.setStorageSync(_AppConfigKey, JSON.stringify(DefaultAppConfigs))
  20. return DefaultAppConfigs;
  21. }
  22. /**
  23. * 保存应用设置
  24. */
  25. export const setAppConfigs = (configs) => {
  26. uni.setStorageSync(_AppConfigKey, JSON.stringify(configs))
  27. }
  28. /**
  29. * 获取应用模拟数据
  30. */
  31. export const getAppMockJson = () => {
  32. let json = uni.getStorageSync(_AppMockJsonKey)
  33. if (json) return JSON.parse(json)
  34. uni.setStorageSync(_AppMockJsonKey, JSON.stringify({}))
  35. return {};
  36. }
  37. /**
  38. * 保存应用模拟数据
  39. */
  40. export const setAppMockJson = (json) => {
  41. uni.setStorageSync(_AppMockJsonKey, JSON.stringify(json))
  42. }