index.js 5.8 KB

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