window.namespace = function (p) {
  p = p.split('.')
  let o = window
  for (let i = 0; i < p.length; ++i) {
    o = o[p[i]] = o[p[i]] || {}
  }
  return o
}
window.zving = window.zving || {}

window.Object.assignIf = window.Object.assignIf || function (target, source) {
  if (typeof target === 'undefined') {
    return source
  }
  if (typeof source !== 'object' && !Array.isArray(source)) {
    return source
  }
  let from
  let to = Object(target)
  let symbols

  for (let s = 1; s < arguments.length; s++) {
    from = Object(arguments[s])
    for (let key in from) {
      if (from.hasOwnProperty(key) && typeof to[key] === 'undefined') {
        to[key] = from[key]
      }
    }

    if (Object.getOwnPropertySymbols) {
      symbols = Object.getOwnPropertySymbols(from)
      for (var i = 0; i < symbols.length; i++) {
        if (from.propertyIsEnumerable(symbols[i]) && typeof to[symbols[i]] === 'undefined') {
          to[symbols[i]] = from[symbols[i]]
        }
      }
    }
  }

  return to
}

let pathName = window.location.pathname.substring(1)
let CONTEXTPATH = pathName === '' || pathName === undefined ? '' : pathName.substring(0, pathName.indexOf('/'))
var SERVERURL = window.location.origin
if (CONTEXTPATH) {
  CONTEXTPATH = '/' + CONTEXTPATH + '/'
  SERVERURL = window.location.origin + CONTEXTPATH
}

// 配置
export default {
  CONTEXTPATH: CONTEXTPATH,
  SERVERURL: SERVERURL,
  axios: {
    baseURL: CONTEXTPATH,
    timeout: 30000,
    headers: {
      post: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
      }
    },
    withCredentials: true
  },
  product: {
    appName: 'ZCMS',
    appName_cn: '泽元内容管理系统',
    companyName: '泽元软件'
  }
}
