import store from '../store'

export function getRootPath() {
  // 获取当前网址，如： http://localhost:8088/test/test.jsp
  var curPath = window.document.location.href
  // 获取主机地址之后的目录，如： test/test.jsp
  var pathName = window.document.location.pathname
  var pos = curPath.indexOf(pathName)
  // 获取主机地址，如： http://localhost:8088
  var localhostPath = curPath.substring(0, pos)
  // 获取带"/"的项目名，如：/test
  var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1)
  return (projectName)
}

/**
 * 判断是否被门户嵌套了
 */
export function isMenHu() {
  let isNotcross = false
  try {
    parent.location.href
    window.parent.document
  } catch (e) {
    isNotcross = true
  }
  return isNotcross
}

/**
 * 判断是否统一门户
 */
export function isMenHu_Unite() {
  if (document.location.search.indexOf('ticket=') !== -1) {
    if (!store.state.app.ticket) {
      store.commit('app/SET_TICKET', document.location.search.replace(new RegExp(/\?unite=1&ticket=/g, 'g')))
      return true
    }
    return false
  }

  return document.location.search.indexOf('unite=1') !== -1

}
