UNPKG

icx-meum-vue-common-module

Version:

icx-meum-vue-common-module

33 lines (30 loc) 1.19 kB
import { getPersonInfo } from '../service/service' import { INT_REQUEST_OK, COOKIE_PERSON_ID, COOKIE_CURRENT_PERSON_ID, INT_REQUEST_NOT_RIGHT, INT_REQUEST_NOT_EXIST } from '../icx/const' import VueCookie from 'vue-cookie' import { GET_PERSON_INFO } from './mutation-types.js' const actions = { async getPerson ({commit, state}, payload) { let res = await getPersonInfo(payload) if (res.errorCode === INT_REQUEST_OK) { if (payload === '') { if (VueCookie.get(COOKIE_PERSON_ID) != res.data.personId) { VueCookie.set(COOKIE_PERSON_ID, res.data.personId, { expires: 7 }) } if (!VueCookie.get(COOKIE_CURRENT_PERSON_ID)) { VueCookie.set(COOKIE_CURRENT_PERSON_ID, res.data.personId, { expires: '1D' }) } } commit(GET_PERSON_INFO, res.data) } else if (res.errorCode === INT_REQUEST_NOT_RIGHT || res.errorCode === INT_REQUEST_NOT_EXIST) { // 如果提示没有权限或者不存在,就删除current_person_id VueCookie.delete(COOKIE_CURRENT_PERSON_ID) actions.getPerson({commit, state}, '') } else { commit(GET_PERSON_INFO, null) } return res } } export default actions