user.js 1.83 KB
Newer Older
潘琦 committed
1
import { getStore, setStore } from '@/util/store'
潘琦 committed
2 3 4

const user = {
  state: {
潘琦 committed
5 6 7 8 9 10 11 12 13
    access_token: getStore({
      name: 'access_token'
    }) || '',
    user_id: getStore({
      name: 'user_id'
    }) || '',
    code: getStore({
      name: 'code'
    }) || '',
潘琦 committed
14 15 16 17 18 19
    authId: getStore({
      name: 'auth_id'
    }) || '',
    accountId: getStore({
      name: 'account_id'
    }) || '',
潘琦 committed
20 21 22
    userInfo: {}
  },
  actions: {
潘琦 committed
23 24 25 26 27 28 29 30 31 32 33
    setToken ({ commit }, param) {
      commit('SET_TOKEN', param)
    },
    setUserId ({ commit }, param) {
      commit('SET_USERID', param)
    },
    setCode ({ commit }, param) {
      commit('SET_CODE', param)
    },
    setAuthId ({ commit }, param) {
      commit('SET_AUTHID', param)
潘琦 committed
34 35 36
    },
    setAccountId ({ commit }, param) {
      commit('SET_ACCOUNTID', param)
潘琦 committed
37
    }
潘琦 committed
38 39
  },
  mutations: {
潘琦 committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    SET_TOKEN: (state, token) => {
      state.access_token = token
      console.log(state.access_token)
      setStore({
        name: 'access_token',
        content: state.access_token,
        type: 'session'
      })
    },
    SET_USERID: (state, userid) => {
      state.user_id = userid
      setStore({
        name: 'user_id',
        content: state.user_id,
        type: 'session'
      })
    },
    SET_CODE: (state, code) => {
      state.code = code
      setStore({
        name: 'code',
        content: state.code,
        type: 'session'
      })
    },
    SET_AUTHID: (state, authId) => {
      state.authId = authId
      setStore({
潘琦 committed
68
        name: 'auth_id',
潘琦 committed
69 70 71 72
        content: state.authId,
        type: 'session'
      })
    },
潘琦 committed
73 74 75 76 77 78 79 80
    SET_ACCOUNTID: (state, accountId) => {
      state.accountId = accountId
      setStore({
        name: 'account_id',
        content: state.accountId,
        type: 'session'
      })
    },
潘琦 committed
81 82 83 84 85 86
    SET_USERIFNO: (state, userInfo) => {
      state.userInfo = userInfo
    }
  }
}
export default user