index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. clubType: 0, // 1: 医美机构 2:生美机构 (医美、生美机构类型)
  13. wechatUserInfo: {},
  14. cartNumber: 0,
  15. isIphoneX: false,
  16. isActivity: false,
  17. isLoginType: 0,
  18. isLoginProductId: 0
  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. state.wechatUserInfo = provider
  42. uni.setStorage({ //缓存用户登陆状态
  43. key: 'wechatUserInfo',
  44. data: provider
  45. })
  46. uni.setStorageSync('_WX_State', 1)
  47. },
  48. updateStatus(state, provider) {
  49. let TIME = api.formatDate()
  50. console.log(`${TIME}`, provider)
  51. state.userInfo = provider
  52. if (state.userInfo) {
  53. state.clubType = provider.firstClubType
  54. if (provider.userIdentity) {
  55. state.identity = provider.userIdentity
  56. } else if (provider.userId == 5261 || provider.userId == 10947 || provider.userId == 11579) {
  57. state.identity = 1
  58. } else if (provider.firstClubType == 1) {
  59. state.identity = 5
  60. } else {
  61. state.identity = 0
  62. }
  63. }
  64. console.log('用户类型', state.identity)
  65. uni.setStorage({ //缓存用户登陆状态
  66. key: 'userInfo',
  67. data: provider
  68. })
  69. },
  70. updateAllNum(state, num) {
  71. if (num >= 100) {
  72. uni.setTabBarBadge({
  73. index: 2,
  74. text: '99+'
  75. })
  76. } else if (num > 0) {
  77. uni.setTabBarBadge({
  78. index: 2,
  79. text: String(num)
  80. })
  81. } else {
  82. uni.removeTabBarBadge({
  83. index: 2,
  84. })
  85. }
  86. },
  87. setActivity(state, variable) { // 记录活动弹窗状态
  88. state.isActivity = variable
  89. },
  90. setChangeVar(state, variable) {
  91. state.isIphoneX = variable
  92. },
  93. setIsIphone(state, variable) { // 记录设备信息是否为IphoneX
  94. state.isIphone = variable
  95. },
  96. setLoginType(state, variable) { // 记录登录跳转类型
  97. state.isLoginType = variable
  98. console.log(state.isLoginType)
  99. },
  100. setLoginProductId(state, variable) { // 记录跳转商品ID
  101. state.isLoginProductId = variable
  102. console.log(state.isLoginProductId)
  103. },
  104. setLoginOrderId(state, variable) { // 记录跳转订单ID
  105. state.isLoginOrderId = variable
  106. console.log(state.isLoginOrderId)
  107. }
  108. },
  109. actions: {
  110. setVariableFun: function(context, vData) {
  111. context.commit('setChangeVar', vData)
  112. },
  113. setIsIphoneFun: function(context, vData) {
  114. context.commit('setIsIphone', vData)
  115. },
  116. setActivityFn: function(context, vData) {
  117. context.commit('setActivity', vData)
  118. },
  119. // setLoginTypeFn:function(context,vData){
  120. // context.commit('setLoginType',vData)
  121. // }
  122. }
  123. })
  124. export default store