index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * @Description:
  3. * @Author: 欧阳承珺
  4. * @LastEditors: 欧阳承珺
  5. * @Date: 2022-10-25 17:19:19
  6. * @LastEditTime: 2022-11-02 16:03:41
  7. */
  8. export const state = () => ({
  9. userInfo: {
  10. memberInfo: {},
  11. pricingList: [],
  12. setPricingList: [],
  13. },
  14. token: '',
  15. globalLoginVisiable: false,
  16. globalInterfaceType: false
  17. })
  18. export const mutations = {
  19. setUser(state, data) {
  20. state.userInfo = data
  21. },
  22. SET_TOKEN(state, data) {
  23. state.token = data
  24. },
  25. DEL_TOKEN(state,data) {
  26. state.token = data
  27. },
  28. OPEN_LOGIN(state, data) {
  29. state.globalLoginVisiable = data
  30. },
  31. SET_INTERFACE(state, data) {
  32. state.globalInterfaceType = data
  33. }
  34. }
  35. export const actions = {
  36. nuxtServerInit ({commit, state}, {req}) {
  37. if (req && req.headers && req.headers.token) {
  38. commit('SET_TOKEN', req.headers.token)
  39. }
  40. },
  41. login ({ commit }, params) {
  42. return new Promise((resolve, reject) => {
  43. this.$axios.get(`auth/getToken?code=${params}`).then(res => {
  44. const token = res.result.accessToken
  45. localStorage.setItem('token',token)
  46. commit('SET_TOKEN', token)
  47. resolve(token)
  48. }).catch(err => {
  49. reject(err)
  50. })
  51. })
  52. },
  53. }