index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import Vuex from 'vuex';
  2. import http from '../plugins/http';
  3. export default new Vuex.Store({
  4. state: {
  5. sessionKey: '',
  6. safeArea: {
  7. top: 0,
  8. botton: 0
  9. },
  10. systemInfo: {
  11. statusBarHeight: 44
  12. },
  13. userInfo: null,
  14. userStoreInfo: null
  15. },
  16. mutations: {
  17. setUserInfo(state, userInfo) {
  18. state.userInfo = userInfo;
  19. },
  20. setSessionKey(state, sessionKey) {
  21. state.sessionKey = sessionKey;
  22. },
  23. setSystemInfo(state, systemInfo) {
  24. state.çç = systemInfo;
  25. },
  26. setUserStoreInfo(state, userStoreInfo) {
  27. state.userStoreInfo = userStoreInfo;
  28. }
  29. },
  30. actions: {
  31. getUserInfo(context) {
  32. return http.http.get('/user/my').then(res => {
  33. console.log(res)
  34. if (res.sex || res.nickname.indexOf('用户') === -1) {
  35. context.commit('setUserInfo', res);
  36. } else {
  37. context.commit('setUserInfo', null);
  38. }
  39. return Promise.resolve(res);
  40. });
  41. },
  42. getUserStore(context) {
  43. if (!context.state.userInfo) {
  44. return Promise.reject();
  45. }
  46. return http.http
  47. .postJson('/store/all', {
  48. query: {
  49. userId: context.state.userInfo.id
  50. }
  51. })
  52. .then(res => {
  53. if (res.empty) {
  54. context.commit('setUserStoreInfo', null);
  55. return Promise.reject();
  56. } else {
  57. context.commit('setUserStoreInfo', res.content[0]);
  58. return Promise.resolve(res.content[0]);
  59. }
  60. });
  61. }
  62. }
  63. });