index.js 699 B

12345678910111213141516171819202122232425262728293031323334
  1. import config from '@/config.js'
  2. import defaultConfig from './defaultConfig.js'
  3. // 合并用户配置和默认配置
  4. const options = Object.assign({}, defaultConfig, config)
  5. /**
  6. * 配置文件工具类
  7. * @module Config
  8. * mix: 如需在项目中获取配置项, 请使用本工具类的方法, 不要直接import根目录的config.js
  9. */
  10. export default {
  11. /**
  12. * 获取全部配置
  13. */
  14. all() {
  15. return options
  16. },
  17. /**
  18. * 获取指定配置
  19. * @param {string} key
  20. * @param {mixed} def
  21. */
  22. get(key, def = undefined) {
  23. if (options.hasOwnProperty(key)) {
  24. return options[key]
  25. }
  26. console.error(`检测到不存在的配置项: ${key}`)
  27. return def
  28. }
  29. }