{"size": 1412, "ext": "js", "max_stars_repo_path": "src/store/modules/user/actions.js", "max_stars_repo_name": "yuehanqw/ant-design-vue-pro-my", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/store/modules/user/actions.js", "max_issues_repo_name": "yuehanqw/ant-design-vue-pro-my", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/store/modules/user/actions.js", "max_forks_repo_name": "yuehanqw/ant-design-vue-pro-my", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.6956521739, "max_line_length": 68, "alphanum_fraction": 0.6635977337}
import * as types from './mutation-types'
import { ACCESS_TOKEN, MULTI_ARR, USER_INFO } from './storage-types'
import { generatorDynamicRouter } from '@/router/generator-routers'
import { postAction } from '@/api/api'

export const SetToken = function({ commit }, data) {
  const { value, remember } = data
  if (remember) {
    localStorage.setItem(ACCESS_TOKEN, JSON.stringify(value))
  }
  commit(types.SET_TOKEN, value)
}
export const SetUserInfo = function({ commit }, data) {
  const { value, remember } = data
  if (remember) {
    localStorage.setItem(USER_INFO, JSON.stringify(value))
  }
  commit(types.SET_USER_INFO, value)
}
export const SetUserRouter = function({ commit }, data) {
  return new Promise(resolve => {
    generatorDynamicRouter().then(routers => {
      commit(types.SET_USER_ROUTERS, routers)
      resolve()
    })
  })
}

export const SetLoginout = function({ commit }, data) {
  return new Promise(resolve => {
    postAction('port/sys/logout').then(res => {
      SetToken({ commit }, { remember: true, value: '' })
      SetUserInfo({ commit }, { remember: true, value: {} })
      SetMultiArr({ commit }, { remember: true, value: [] })
      resolve()
    })
  })
}

export const SetMultiArr = function({ commit }, data) {
  const { value, remember } = data
  if (remember) {
    localStorage.setItem(MULTI_ARR, JSON.stringify(value))
  }
  commit(types.SET_MULTI_ARR, value)
}