index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. toolsPlugin: {},
  12. linksSubmitPlugin: {},
  13. },
  14. pageConfig: {}
  15. }
  16. /**
  17. * 获取应用设置
  18. */
  19. export const getAppConfigs = () => {
  20. let configs = uni.getStorageSync(_AppConfigKey)
  21. if (configs) return JSON.parse(configs)
  22. uni.setStorageSync(_AppConfigKey, JSON.stringify(DefaultAppConfigs))
  23. return DefaultAppConfigs;
  24. }
  25. /**
  26. * 保存应用设置
  27. */
  28. export const setAppConfigs = (configs) => {
  29. uni.setStorageSync(_AppConfigKey, JSON.stringify(configs))
  30. }
  31. /**
  32. * 获取应用模拟数据
  33. */
  34. export const getAppMockJson = () => {
  35. let json = uni.getStorageSync(_AppMockJsonKey)
  36. if (json) return JSON.parse(json)
  37. uni.setStorageSync(_AppMockJsonKey, JSON.stringify({}))
  38. return {};
  39. }
  40. /**
  41. * 保存应用模拟数据
  42. */
  43. export const setAppMockJson = (json) => {
  44. uni.setStorageSync(_AppMockJsonKey, JSON.stringify(json))
  45. }