index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import api from '../common/config/caimeiApi.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. state.wechatUserInfo = provider
  41. uni.setStorage({ //缓存用户登陆状态
  42. key: 'wechatUserInfo',
  43. data: provider
  44. })
  45. uni.setStorageSync('_WX_State', 1)
  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 if(provider.firstClubType == 1) {
  57. state.identity = 5
  58. }else{
  59. state.identity = 0
  60. }
  61. }
  62. console.log('用户类型', state.identity)
  63. uni.setStorage({ //缓存用户登陆状态
  64. key: 'userInfo',
  65. data: provider
  66. })
  67. },
  68. updateAllNum(state, num) {
  69. if (num >= 100) {
  70. uni.setTabBarBadge({
  71. index: 2,
  72. text: '99+'
  73. })
  74. } else if (num > 0) {
  75. uni.setTabBarBadge({
  76. index: 2,
  77. text: String(num)
  78. })
  79. } else {
  80. uni.removeTabBarBadge({
  81. index: 2,
  82. })
  83. }
  84. },
  85. setActivity(state, variable) { // 记录活动弹窗状态
  86. state.isActivity = variable
  87. },
  88. setChangeVar(state, variable) {
  89. state.isIphoneX = variable
  90. },
  91. setIsIphone(state, variable) { // 记录设备信息是否为IphoneX
  92. state.isIphone = variable
  93. },
  94. setLoginType(state, variable) { // 记录登录跳转类型
  95. state.isLoginType = variable
  96. console.log(state.isLoginType)
  97. },
  98. setLoginProductId(state, variable) { // 记录跳转商品ID
  99. state.isLoginProductId = variable
  100. console.log(state.isLoginProductId)
  101. },
  102. setLoginOrderId(state, variable) { // 记录跳转订单ID
  103. state.isLoginOrderId = variable
  104. console.log(state.isLoginOrderId)
  105. }
  106. },
  107. actions: {
  108. setVariableFun: function(context, vData) {
  109. context.commit('setChangeVar', vData)
  110. },
  111. setIsIphoneFun: function(context, vData) {
  112. context.commit('setIsIphone', vData)
  113. },
  114. setActivityFn: function(context, vData) {
  115. context.commit('setActivity', vData)
  116. },
  117. // setLoginTypeFn:function(context,vData){
  118. // context.commit('setLoginType',vData)
  119. // }
  120. }
  121. })
  122. export default store