|
@@ -3,8 +3,10 @@
|
|
* @Author: 欧阳承珺
|
|
* @Author: 欧阳承珺
|
|
* @LastEditors: 欧阳承珺
|
|
* @LastEditors: 欧阳承珺
|
|
* @Date: 2022-10-25 17:19:19
|
|
* @Date: 2022-10-25 17:19:19
|
|
- * @LastEditTime: 2022-11-02 16:03:41
|
|
|
|
|
|
+ * @LastEditTime: 2022-11-16 09:25:49
|
|
*/
|
|
*/
|
|
|
|
+import { setToken, cookieParse } from '~/utils/cookie'
|
|
|
|
+
|
|
export const state = () => ({
|
|
export const state = () => ({
|
|
userInfo: {
|
|
userInfo: {
|
|
memberInfo: {},
|
|
memberInfo: {},
|
|
@@ -38,15 +40,22 @@ export const mutations = {
|
|
export const actions = {
|
|
export const actions = {
|
|
|
|
|
|
nuxtServerInit ({commit, state}, {req}) {
|
|
nuxtServerInit ({commit, state}, {req}) {
|
|
- if (req && req.headers && req.headers.token) {
|
|
|
|
- commit('SET_TOKEN', req.headers.token)
|
|
|
|
|
|
+ let token = null
|
|
|
|
+ if (req && req.headers && req.headers.cookie) {
|
|
|
|
+ const parsed = cookieParse(req.headers.cookie)
|
|
|
|
+ try {
|
|
|
|
+ token = parsed.Token
|
|
|
|
+ } catch (err) {
|
|
}
|
|
}
|
|
|
|
+ commit('SET_TOKEN', token)
|
|
|
|
+ }
|
|
},
|
|
},
|
|
|
|
|
|
login ({ commit }, params) {
|
|
login ({ commit }, params) {
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
this.$axios.get(`auth/getToken?code=${params}`).then(res => {
|
|
this.$axios.get(`auth/getToken?code=${params}`).then(res => {
|
|
const token = res.result.accessToken
|
|
const token = res.result.accessToken
|
|
|
|
+ setToken('Token', token)
|
|
localStorage.setItem('token',token)
|
|
localStorage.setItem('token',token)
|
|
commit('SET_TOKEN', token)
|
|
commit('SET_TOKEN', token)
|
|
resolve(token)
|
|
resolve(token)
|