// 获取url参数
function clearString () {
  const args = new Array(...arguments)
  let string = args.shift()
  while (args.length) {
    string = string.split(args[0].str)[args[0].index]
    args.shift()
  }
  return string
}

export const getQueryString = (name) => {
  const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|/#/|$)', 'g')
  const urls = window.location.href.split('?')
  let result = ''
  urls.forEach((url) => {
    const temp = url.match(reg)
    if (!result && temp && temp.length) {
      result = clearString(temp[0],
        { str: `${name}=`, index: 1 },
        { str: '/#/', index: 0 },
        { str: '&', index: 0 })
    }
  })
  return decodeURIComponent(result)
}
