/*
 * 全局设置
 */
export const state = () => ({
  userAgent: '',
  // 是否移动端
  isMobile: false,
  // 身份token
  cookies: '',
  // 用户身份SessionId
  sessionId: '',
  // 正式系统地址
  // url: 'http://218.17.158.219:9090/platform-b2c',
  // 登录信息来源
  appId: '',
  returnUrl: '',
  baseUrl: '',
  inviteSpaceUU: '',
  inviteUserUU: '',
  fullPath: '',
  // 用户信息
  isLogin: {
    // 是否登录
    logged: false,
    fetching: false,
    data: []
  },
  // 获取用户信息
  userInfo: {
    fetching: false,
    data: []
  },
  // 系统设置
  globalOptions: {
    fetching: false,
    data: {}
  }
})

export const mutations = {
  SET_USER_AGENT (state, result) {
    state.userAgent = result
  },
  SET_MOBILE_LAYOUT (state, result) {
    state.isMobile = result
  },
  SET_COOKIES (state, result) {
    state.cookies = result || ''
  },
  SET_SESSION_ID (state, result) {
    state.sessionId = result || ''
  },
  UPDATE_URL (state, result) {
    state.url = result
  },
  SET_APPID (state, result) {
    state.appId = result || ''
  },
  SET_RETURNURL (state, result) {
    state.returnUrl = result || ''
  },
  SET_BASEURL (state, result) {
    state.baseUrl = result || ''
  },
  SET_INVITESPACEUU (state, result) {
    state.inviteSpaceUU = result || ''
  },
  SET_INVITEUSERUU (state, result) {
    state.inviteUserUU = result || ''
  },
  SET_INVITATIONTIME (state, result) {
    state.invitationTime = result || ''
  },
  SET_FULLPATH (state, result) {
    state.fullPath = result || ''
  },
  REQUEST_USER_INFO (state) {
    state.userInfo.fetching = true
  },
  REQUEST_USER_INFO_SUCCESS (state, result) {
    state.userInfo.data = result || {}
    state.userInfo.fetching = false
  },
  REQUEST_USER_INFO_FAILURE (state) {
    state.userInfo.fetching = true
    state.userInfo.data = {}
  },
  REQUEST_IS_LOGIN (state) {
    state.isLogin.fetching = true
  },
  REQUEST_IS_LOGIN_SUCCESS (state, result) {
    state.isLogin.fetching = false
    state.isLogin.data = result || {}
    state.isLogin.logged = !!(result && result.userName)
  },
  REQUEST_IS_LOGIN_FAILURE (state) {
    state.isLogin.fetching = false
    state.isLogin.data = {}
  },
  REQUEST_LOGOUT_SUCCESS (state) {
    state.isLogin.data = {}
    state.isLogin.logged = false
  },
  REQUEST_GLOBAL_OPTIONS (state) {
    state.globalOptions.fetching = true
  },
  REQUEST_GLOBAL_OPTIONS_SUCCESS (state, result) {
    state.globalOptions.fetching = false
    state.globalOptions.data = result
  },
  REQUEST_GLOBAL_OPTIONS_FAILURE (state) {
    state.globalOptions.fetching = false
  }
}
