index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // #ifndef VUE3
  2. import Vue from 'vue'
  3. import Vuex from 'vuex'
  4. Vue.use(Vuex)
  5. let { config } = require('../common/util.js');
  6. const store = new Vuex.Store({
  7. // #endif
  8. // #ifdef VUE3
  9. import { createStore } from 'vuex'
  10. const store = createStore({
  11. // #endif
  12. state: {
  13. hasLogin: false,
  14. isUniverifyLogin: false,
  15. loginProvider: "",
  16. openid: null,
  17. testvuex: false,
  18. colorIndex: 0,
  19. colorList: ['#FF0000', '#00FF00', '#0000FF'],
  20. noMatchLeftWindow: true,
  21. active: 'componentPage',
  22. leftWinActive: '/pages/component/view/view',
  23. activeOpen: '',
  24. menu: [],
  25. univerifyErrorMsg: '',
  26. userInfo: {},
  27. shop: false,
  28. geoinfo: {},
  29. redirctCurCate: ''
  30. },
  31. mutations: {
  32. login(state, data) {
  33. state.hasLogin = true;
  34. state.signature = data.signature;
  35. state.vid = data.vid;
  36. state.uid = data.uid;
  37. },
  38. setUserInfo(state, userInfo) {
  39. state.userInfo = userInfo
  40. },
  41. setShop(state, shop) {
  42. state.shop = shop.id ? shop : null;
  43. },
  44. logout(state) {
  45. state.hasLogin = false
  46. state.openid = null
  47. },
  48. setRedirctCurCate(state, curCate) {
  49. state.redirctCurCate = curCate
  50. }
  51. },
  52. getters: {
  53. currentColor(state) {
  54. return state.colorList[state.colorIndex]
  55. }
  56. },
  57. actions: {
  58. getUser: async function({
  59. commit,
  60. state
  61. }) {
  62. return await new Promise((resolve, reject) => {
  63. if (state.userInfo && state.userInfo.nickName) {
  64. resolve(state.userInfo)
  65. } else {
  66. let baseToken = {};
  67. try {
  68. baseToken = uni.getStorageSync('baseToken')
  69. } catch(e) {
  70. console.error(e)
  71. }
  72. if(!baseToken.t) {
  73. return;
  74. }
  75. commit('setUserInfo', {
  76. ...baseToken
  77. })
  78. }
  79. })
  80. },
  81. }
  82. })
  83. export default store