index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. wechatUserInfo: {}, //用户微信相关信息
  12. cartNumber: 0,
  13. isIphoneX: false,
  14. isActivity: false,
  15. isLoginType: 0,
  16. isLoginProductId: 0,
  17. windowHeight:''
  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.setStorageSync('_WX_State',true)
  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. uni.setStorage({ //缓存用户登陆状态
  53. key: 'userInfo',
  54. data: provider
  55. })
  56. },
  57. updateAllNum(state, num) {
  58. if (num >= 100) {
  59. uni.setTabBarBadge({
  60. index: 1,
  61. text: '99+'
  62. })
  63. } else if (num > 0) {
  64. uni.setTabBarBadge({
  65. index: 1,
  66. text: String(num)
  67. })
  68. } else {
  69. uni.removeTabBarBadge({
  70. index: 1,
  71. })
  72. }
  73. },
  74. setActivity(state, variable) {
  75. state.isActivity = variable
  76. },
  77. setChangeVar(state, variable) {
  78. //获取设备信息是否为IphoneX
  79. state.isIphoneX = variable
  80. },
  81. setIsIphone(state, variable) {
  82. //获取设备信息是否为IphoneX
  83. state.isIphone = variable
  84. },
  85. setLoginType(state, variable) {
  86. //获取设备信息是否为IphoneX
  87. state.isLoginType = variable
  88. console.log(state.isLoginType)
  89. },
  90. setLoginProductId(state, variable) {
  91. //获取设备信息是否为IphoneX
  92. state.isLoginProductId = variable
  93. console.log(state.isLoginProductId)
  94. },
  95. setLoginOrderId(state, variable) {
  96. //获取设备信息是否为IphoneX
  97. state.isLoginOrderId = variable
  98. console.log(state.isLoginOrderId)
  99. },
  100. setWindowHeight(state,height){
  101. state.windowHeight = height
  102. console.log(state.windowHeight)
  103. }
  104. },
  105. actions: {
  106. setVariableFun: function(context, vData) {
  107. context.commit('setChangeVar', vData)
  108. },
  109. setIsIphoneFun: function(context, vData) {
  110. context.commit('setIsIphone', vData)
  111. },
  112. setActivityFn: function(context, vData) {
  113. context.commit('setActivity', vData)
  114. },
  115. // setLoginTypeFn:function(context,vData){
  116. // context.commit('setLoginType',vData)
  117. // }
  118. }
  119. })
  120. export default store