path.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * 获取resource目录地址
  3. * @returns String
  4. */
  5. function GetResourcePath() {
  6. let e = document.location.toString()
  7. return e.match(/^(?<root>.*\/resource\/)/).groups.root
  8. }
  9. /**
  10. * 获取url请求参数
  11. * @returns Object
  12. */
  13. function getQueryParams() {
  14. if (location.search.indexOf('?') > -1) {
  15. var querys = location.search.substr(1).split('&')
  16. var obj = {}
  17. querys.forEach((element) => {
  18. var arr = element.split('=')
  19. obj[arr[0]] = decodeURIComponent(arr[1])
  20. })
  21. return obj
  22. }
  23. return {}
  24. }
  25. /**
  26. * 返回当前环境的路径间隔符
  27. * @returns String
  28. */
  29. function GetDirSpacer() {
  30. return IsWindows() ? '\\' : '/'
  31. }
  32. function IsWindows() {
  33. return window.navigator.platform.toLocaleLowerCase().indexOf('win') > -1
  34. }
  35. function mkdir(dir) {
  36. var dirs = dir.split(constStrEnum.DirSeparator)
  37. var current = ''
  38. for (var idx = 0; idx < dirs.length; idx++) {
  39. current += dirs[idx] + constStrEnum.DirSeparator
  40. if (!wps.FileSystem.Exists(current))
  41. if (!wps.FileSystem.Mkdir(current)) throw Error('无法创建目录' + current)
  42. }
  43. }