app.js 1.93 KB
/*
 * @Descripttion:
 * @version:
 * @Author: limin
 * @Date: 2021-06-07 14:12:32
 * @LastEditors: limin
 * @LastEditTime: 2021-07-06 12:02:21
 */
import { store, util } from 'utils'
import { Http } from 'glsx-common'
import { Notify } from 'vant'
const state = {
  pageMeta: '',
  keepAlives: [],
  lastPath: ''
}
const mutations = {
  SET_PAGE_META(state, meta) {
    state.pageMeta = meta
  },
  PUSH_KEEP(state, name) {
    if (!state.keepAlives.includes(name)) {
      state.keepAlives.push(name)
    }
  },
  REMOVE_KEEP(state, names) {
    state.keepAlives = state.keepAlives.reduce((arr, name) => {
      if (!names.includes(name)) {
        return arr.push(name)
      }
      return arr
    }, [])
  },
  SET_LAST_PATH(state, path) {
    state.lastPath = path
  }
}
const actions = {
  setPageMeta({ commit }, meta) {
    document.title = meta.title
    commit('SET_PAGE_META', meta)
  },
  setLoginToken({ commit }, val) {
    commit('SET_LOGIN_TOKEN', val)
  },
  setAccountList({ commit }, list) {
    commit('SET_ACCOUNT_LIST', list)
  },
  pushKeep({ commit }, name) {
    commit('PUSH_KEEP', name)
  },
  removeKeep({ commit }, names) {
    commit('REMOVE_KEEP', names)
  },
  login({ dispatch }) {
    
  },
  navigation({ dispatch }) {
    dispatch('registerHttp')
    state.showWindow = true
  },
  registerHttp({}) {
    const sessionId = getParams('sId')
    window.$HTTP = new Http({ ...window.$fetchConfig, alert: Notify, headers: { token: sessionId } })
    // window.$HTTP = new Http({ ...window.$fetchConfig, alert: Notify, headers: { token: 'scrm-base-f9688caa-36ac-4795-8b91-d38e17c7ccc3-rop' } })
  }
}
const getParams = name => {
  let [url, paramsList] = window.location.href.split('?')
  if (!paramsList) return name ? null : {}
  let param = paramsList.split('&')
  let obj = {}
  param.map(e => {
    let [key, value] = e.split('=')
    obj[key] = value
  })
  return name ? obj[name] : obj
}
export default {
  state,
  mutations,
  actions
}