index.js 3.2 KB

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