index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. import * as caimeiApi from '@/common/config/caimeiApi.js'
  6. import ajaxService from '@/services/ajax.service.js'
  7. import UserService from '@/services/user.service.js'
  8. Vue.use(Vuex)
  9. const store = new Vuex.Store({
  10. state: {
  11. isWxAuthorize: false,
  12. hasLogin: false,
  13. userInfo: {},
  14. identity: 0,
  15. noticeNum:0,
  16. clubType: 0, // 1: 医美机构 2:生美机构 (医美、生美机构类型)
  17. wechatUserInfo: {},
  18. cartNumber: 0,
  19. isIphoneX: false,
  20. isActivity: false,
  21. isLoginType: 0,
  22. isLoginProductId: 0
  23. },
  24. mutations: {
  25. login(state, provider) { //用户身份 1、协销 2、资质机构 3、供应商 4.个人机构
  26. state.hasLogin = true
  27. state.userInfo = provider
  28. uni.setStorage({ //缓存用户登陆状态
  29. key: 'userInfo',
  30. data: provider
  31. })
  32. },
  33. logout(state) {
  34. state.hasLogin = false
  35. state.userInfo = {}
  36. uni.removeStorage({
  37. key: 'userInfo'
  38. })
  39. uni.removeStorage({
  40. key: 'token'
  41. })
  42. },
  43. wxLogin(state, provider) {
  44. state.isWxAuthorize = true
  45. state.wechatUserInfo = provider
  46. uni.setStorage({ //缓存用户登陆状态
  47. key: 'wechatUserInfo',
  48. data: provider
  49. })
  50. uni.setStorageSync('_WX_State', 1)
  51. },
  52. updateStatus(state, provider) {
  53. let TIME = api.formatDate()
  54. console.log(`${TIME}`, provider)
  55. state.userInfo = provider
  56. if (state.userInfo) {
  57. state.clubType = provider.firstClubType
  58. state.identity = provider.userIdentity
  59. if (provider.userId == 5261 || provider.userId == 10947 || provider.userId == 11579) {
  60. state.identity = 1
  61. } else if (provider.firstClubType == 1) {
  62. state.identity = 5
  63. } else {
  64. state.identity = 0
  65. }
  66. }
  67. console.log('用户类型', state.identity)
  68. uni.setStorage({ //缓存用户登陆状态
  69. key: 'userInfo',
  70. data: provider
  71. })
  72. },
  73. async updateNoticeNum(state) { // 更新通知消息数量
  74. console.log('全部更新通知消息数量')
  75. const getUserService = new UserService(ajaxService)
  76. const userInfo = await caimeiApi.getStorage()
  77. const commonId = userInfo.clubId ? userInfo.clubId : 0
  78. getUserService.getAuthClubCount({ commonId: commonId })
  79. .then(response => {
  80. state.noticeNum = response.data.count
  81. if (state.noticeNum >= 100) {
  82. uni.setTabBarBadge({
  83. index: 2,
  84. text: '99+'
  85. })
  86. } else if (state.noticeNum > 0) {
  87. uni.setTabBarBadge({
  88. index: 2,
  89. text: String(state.noticeNum)
  90. })
  91. } else {
  92. uni.removeTabBarBadge({
  93. index: 2,
  94. })
  95. }
  96. })
  97. .catch(error => {
  98. uni.removeTabBarBadge({
  99. index: 2,
  100. })
  101. })
  102. },
  103. updateAllNum(state, num) {
  104. if (num >= 100) {
  105. uni.setTabBarBadge({
  106. index: 3,
  107. text: '99+'
  108. })
  109. } else if (num > 0) {
  110. uni.setTabBarBadge({
  111. index: 3,
  112. text: String(num)
  113. })
  114. } else {
  115. uni.removeTabBarBadge({
  116. index: 3,
  117. })
  118. }
  119. },
  120. setActivity(state, variable) { // 记录活动弹窗状态
  121. state.isActivity = variable
  122. },
  123. setChangeVar(state, variable) {
  124. state.isIphoneX = variable
  125. },
  126. setIsIphone(state, variable) { // 记录设备信息是否为IphoneX
  127. state.isIphone = variable
  128. },
  129. setLoginType(state, variable) { // 记录登录跳转类型
  130. state.isLoginType = variable
  131. console.log(state.isLoginType)
  132. },
  133. setLoginProductId(state, variable) { // 记录跳转商品ID
  134. state.isLoginProductId = variable
  135. console.log(state.isLoginProductId)
  136. },
  137. setLoginOrderId(state, variable) { // 记录跳转订单ID
  138. state.isLoginOrderId = variable
  139. console.log(state.isLoginOrderId)
  140. }
  141. },
  142. actions: {
  143. setVariableFun: function(context, vData) {
  144. context.commit('setChangeVar', vData)
  145. },
  146. setIsIphoneFun: function(context, vData) {
  147. context.commit('setIsIphone', vData)
  148. },
  149. setActivityFn: function(context, vData) {
  150. context.commit('setActivity', vData)
  151. },
  152. // setLoginTypeFn:function(context,vData){
  153. // context.commit('setLoginType',vData)
  154. // }
  155. }
  156. })
  157. export default store