index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. const store = new Vuex.Store({
  5. state: {
  6. hasLogin: false,
  7. userInfo: {},
  8. storageId: -1,
  9. spread: 0,
  10. cartNum: 0,
  11. storageObj: {},
  12. InvitationCode: '',
  13. $deviceType: null,
  14. headerTop: '',
  15. isWeixin: false
  16. },
  17. mutations: {
  18. login(state, provider) {
  19. state.hasLogin = true;
  20. state.userInfo = provider;
  21. uni.setStorageSync('userInfo', provider)
  22. },
  23. logout(state) {
  24. state.hasLogin = false;
  25. state.userInfo = {};
  26. uni.removeStorageSync('userInfo')
  27. },
  28. setStorage(state, id) {
  29. state.storageId = id
  30. },
  31. setSpread(state, id) {
  32. state.spread = id
  33. },
  34. setStorageCode(state, InvitationCode) {
  35. state.InvitationCode = InvitationCode
  36. },
  37. setStorageObj(state, obj) {
  38. state.storageObj = obj
  39. },
  40. updateDevicetype(state, $deviceType) {
  41. state.$deviceType = $deviceType
  42. },
  43. addCart(state, num) {
  44. state.cartNum = num
  45. },
  46. setIsWeixin(state) {
  47. var ua = navigator.userAgent.toLowerCase();
  48. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  49. state.isWeixin = true
  50. } else {
  51. state.isWeixin = false
  52. }
  53. }
  54. },
  55. actions: {
  56. },
  57. getters: {
  58. getUserInfo(state) {
  59. return state.userInfo
  60. }
  61. }
  62. })
  63. export default store