index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import login from '@/apis/login'
  4. import common from '@/apis/common'
  5. Vue.use(Vuex);
  6. export default new Vuex.Store({
  7. //所有的数据都放在state中
  8. state: {
  9. applyData: {}, //预约考试数据存放
  10. token: '',
  11. user_account: '',
  12. userInfo: null,
  13. checkGoodsList: [],
  14. examResult:{},
  15. header: {
  16. serviceTel: {}
  17. },//页头配置
  18. footer: [],//页尾配置
  19. links: null,//友情链接
  20. },
  21. getters: {
  22. userInfo: state => state.userInfo,
  23. token: state => state.token,
  24. checkGoodsList: state => state.checkGoodsList,
  25. header: state => state.header,
  26. footer: state => state.footer,
  27. links: state => state.links,
  28. getApplyData: state => state.applyData,
  29. examResult: state => state.examResult,
  30. },
  31. //操作数据,唯一的通道是mutations
  32. mutations: {
  33. setExamResult(state,data) {
  34. state.examResult = data;
  35. },
  36. updateApplyData(state, data) {
  37. state.applyData = data;
  38. },
  39. setUserInfo(state, data) {
  40. state.userInfo = data;
  41. },
  42. setCheckGoodsList(state, data) {
  43. state.checkGoodsList = data;
  44. },
  45. setHomeSetList(state, data) {
  46. data.forEach(item => {
  47. if (item.configKey === 'home.header') {
  48. state.header = JSON.parse(item.configValue)
  49. console.log(state.header)
  50. }
  51. if (item.configKey === 'home.footer') {
  52. state.footer = JSON.parse(item.configValue)
  53. console.log(state.footer)
  54. }
  55. if (item.configKey === 'home.links') {
  56. state.links = JSON.parse(item.configValue)
  57. console.log(state.links)
  58. }
  59. })
  60. }
  61. },
  62. //actions,可以来做异步操作,然后提交给mutations,而后再对state(数据)进行操作
  63. actions: {
  64. /**
  65. *
  66. * @param {*} context
  67. * @returns
  68. * 获取用户信息
  69. */
  70. getUserInfo(context) {
  71. return new Promise(resolve => {
  72. login.getInfo().then(res => {
  73. context.commit('setUserInfo', res.data)
  74. resolve()
  75. })
  76. })
  77. },
  78. /**
  79. *
  80. * @param {*} context
  81. * @returns
  82. * 获取首页配置
  83. */
  84. getCommonBaseHomeList(context) {
  85. return new Promise(resolve => {
  86. common.getCommonBaseHomeList().then(res => {
  87. context.commit('setHomeSetList', res.rows)
  88. resolve()
  89. })
  90. })
  91. }
  92. }
  93. })