123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /*
- * @Description:
- * @Author: 欧阳承珺
- * @LastEditors: 欧阳承珺
- * @Date: 2022-10-25 17:19:19
- * @LastEditTime: 2022-11-16 13:51:41
- */
- import { setToken, cookieParse } from '~/utils/cookie'
- export const state = () => ({
- userInfo: {},
- token: '',
- globalLoginVisiable: false,
- globalInterfaceType: false
- })
- export const mutations = {
- setUser(state, data) {
- if(!data.avatarUrl && Object.keys(data).length !== 0){
- if(data.subscriberType === 1){
- data.avatarUrl = " http://data-center-mainland-dev.oss-cn-shanghai.aliyuncs.com/avatars/2023/01/03/0577b907be980556bdafa23fb0be0732-jpg.jpg"
- }else{
- data.avatarUrl = "http://data-center-mainland-dev.oss-cn-shanghai.aliyuncs.com/avatars/2023/01/03/f183029426a996325853fa244e7df661-jpg.jpg"
- }
- }
- state.userInfo = data
- },
- SET_TOKEN(state, data) {
- state.token = data
- },
- DEL_TOKEN(state,data) {
- state.token = data
- },
- OPEN_LOGIN(state, data) {
- state.globalLoginVisiable = data
- },
- SET_INTERFACE(state, data) {
- state.globalInterfaceType = data
- }
- }
- export const actions = {
- nuxtServerInit ({commit, state}, {req}) {
- let token = null
- let userInfo = null
- if (req && req.headers && req.headers.cookie) {
- const parsed = cookieParse(req.headers.cookie)
- try {
- token = parsed?.Token || ''
- userInfo = JSON.parse(decodeURIComponent(parsed.vuex)).userInfo
- } catch (err) {
- }
- commit('SET_TOKEN', token)
- }
- },
- login ({ commit }, params) {
- return new Promise((resolve, reject) => {
- this.$axios.get(`auth/getToken?code=${params}`).then(res => {
- const token = res.result.accessToken
- setToken('Token', token)
- localStorage.setItem('token',token)
- commit('SET_TOKEN', token)
- resolve(token)
- }).catch(err => {
- reject(err)
- })
- })
- },
- }
|