index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import api from '../common/config/utilsTools.js'
  4. import authorize from '../common/config/authorize.js'
  5. Vue.use(Vuex)
  6. const store = new Vuex.Store({
  7. state: {
  8. isWxAuthorize: false,
  9. hasLogin: false,
  10. userInfo: {},
  11. identity: 0,
  12. wechatUserInfo: {},
  13. cartNumber: 0,
  14. isIphoneX: false,
  15. isActivity: false,
  16. isLoginType: 0,
  17. isLoginProductId: 0
  18. },
  19. mutations: {
  20. login(state, provider) { //用户身份 1、协销 2、会员机构 3、供应商 4.普通机构
  21. state.hasLogin = true
  22. state.userInfo = provider
  23. uni.setStorage({ //缓存用户登陆状态
  24. key: 'userInfo',
  25. data: provider
  26. })
  27. },
  28. logout(state) {
  29. state.hasLogin = false
  30. state.userInfo = {}
  31. uni.removeStorage({
  32. key: 'userInfo'
  33. })
  34. uni.removeStorage({
  35. key: 'token'
  36. })
  37. },
  38. wxLogin(state, provider) {
  39. state.isWxAuthorize = true
  40. // console.log(state.isWxAuthorize)
  41. state.wechatUserInfo = provider
  42. uni.setStorage({ //缓存用户登陆状态
  43. key: 'wechatUserInfo',
  44. data: provider
  45. })
  46. },
  47. updateStatus(state, provider) {
  48. let TIME = api.formatDate()
  49. console.log(`${TIME}`, provider)
  50. state.userInfo = provider
  51. if (state.userInfo) {
  52. if (provider.userIdentity) {
  53. state.identity = provider.userIdentity
  54. } else if (provider.userID == 5261 || provider.userID == 10947 || provider.userID == 11579) {
  55. state.identity = 1
  56. } else {
  57. state.identity = 0
  58. }
  59. }
  60. console.log('用户类型', state.identity)
  61. uni.setStorage({ //缓存用户登陆状态
  62. key: 'userInfo',
  63. data: provider
  64. })
  65. },
  66. updateAllNum(state, num) {
  67. if (num >= 100) {
  68. uni.setTabBarBadge({
  69. index: 2,
  70. text: '99+'
  71. })
  72. } else if (num > 0) {
  73. uni.setTabBarBadge({
  74. index: 2,
  75. text: String(num)
  76. })
  77. } else {
  78. uni.removeTabBarBadge({
  79. index: 2,
  80. })
  81. }
  82. },
  83. setActivity(state, variable) {
  84. state.isActivity = variable
  85. },
  86. setChangeVar(state, variable) {
  87. //获取设备信息是否为IphoneX
  88. state.isIphoneX = variable
  89. },
  90. setIsIphone(state, variable) {
  91. //获取设备信息是否为IphoneX
  92. state.isIphone = variable
  93. },
  94. setLoginType(state, variable) {
  95. //获取设备信息是否为IphoneX
  96. state.isLoginType = variable
  97. console.log(state.isLoginType)
  98. },
  99. setLoginProductId(state, variable) {
  100. //获取设备信息是否为IphoneX
  101. state.isLoginProductId = variable
  102. console.log(state.isLoginProductId)
  103. },
  104. setLoginOrderId(state, variable) {
  105. //获取设备信息是否为IphoneX
  106. state.isLoginOrderId = variable
  107. console.log(state.isLoginOrderId)
  108. }
  109. },
  110. actions: {
  111. setVariableFun: function(context, vData) {
  112. context.commit('setChangeVar', vData)
  113. },
  114. setIsIphoneFun: function(context, vData) {
  115. context.commit('setIsIphone', vData)
  116. },
  117. setActivityFn: function(context, vData) {
  118. context.commit('setActivity', vData)
  119. },
  120. // setLoginTypeFn:function(context,vData){
  121. // context.commit('setLoginType',vData)
  122. // }
  123. }
  124. })
  125. export default store