index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. const getUserService = new UserService(ajaxService)
  9. Vue.use(Vuex)
  10. const store = new Vuex.Store({
  11. state: {
  12. isWxAuthorize: false,
  13. hasLogin: false,
  14. userInfo: {},
  15. identity: 0,
  16. noticeNum:0,
  17. clubType: 0, // 1: 医美机构 2:生美机构 (医美、生美机构类型)
  18. wechatUserInfo: {},
  19. cartNumber: 0,
  20. isIphoneX: false,
  21. isActivity: false,
  22. isLoginType: 0,
  23. isLoginProductId: 0,
  24. isManage: false,// 是否是管理员或者小组长
  25. isRossShow:false // 是否显示ross广告图
  26. },
  27. mutations: {
  28. login(state, provider) { //用户身份 1、协销 2、资质机构 3、供应商 4.个人机构
  29. state.hasLogin = true
  30. state.userInfo = provider
  31. uni.setStorage({ //缓存用户登陆状态
  32. key: 'userInfo',
  33. data: provider
  34. })
  35. },
  36. logout(state) {
  37. state.hasLogin = false
  38. state.userInfo = {}
  39. uni.removeStorage({
  40. key: 'userInfo'
  41. })
  42. uni.removeStorage({
  43. key: 'token'
  44. })
  45. },
  46. wxLogin(state, provider) {
  47. state.isWxAuthorize = true
  48. state.wechatUserInfo = provider
  49. uni.setStorage({ //缓存用户登陆状态
  50. key: 'wechatUserInfo',
  51. data: provider
  52. })
  53. uni.setStorageSync('_WX_State', 1)
  54. },
  55. updateStatus(state, provider) {
  56. let TIME = api.formatDate()
  57. console.log(`${TIME}`, provider)
  58. state.userInfo = provider
  59. if (state.userInfo) {
  60. state.clubType = provider.firstClubType
  61. state.identity = provider.userIdentity
  62. // 判断登录用户为协销 设置管理员组长权限
  63. if(provider.userIdentity === 1){
  64. if(provider.manager>0 || provider.leaderId > 0){
  65. state.isManage = true
  66. }
  67. }
  68. // 判断以下公司账户设置部分权限
  69. if (provider.userId == 5261 || provider.userId == 10947 || provider.userId == 11579) {
  70. state.identity = 1
  71. } else if (provider.firstClubType == 1) {
  72. state.identity = 5
  73. } else {
  74. state.identity = 0
  75. }
  76. }
  77. uni.setStorage({ //缓存用户登陆状态
  78. key: 'userInfo',
  79. data: provider
  80. })
  81. },
  82. async updateNoticeNum(state) { // 更新通知消息数量
  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. async updateRossShow(state){
  111. const USER_EVEN = await caimeiApi.getStorage()
  112. if(USER_EVEN.userIdentity === 1) { return }
  113. getUserService.userInformationVisitRoos({ userId: USER_EVEN.userId ? USER_EVEN.userId : 0 })
  114. .then(response => {
  115. state.isRossShow = response.data
  116. })
  117. .catch(error => {
  118. console.log(error)
  119. })
  120. },
  121. updateAllNum(state, num) {
  122. if (num >= 100) {
  123. uni.setTabBarBadge({
  124. index: 1,
  125. text: '99+'
  126. })
  127. } else if (num > 0) {
  128. uni.setTabBarBadge({
  129. index: 1,
  130. text: String(num)
  131. })
  132. } else {
  133. uni.removeTabBarBadge({
  134. index: 1,
  135. })
  136. }
  137. },
  138. setActivity(state, variable) { // 记录活动弹窗状态
  139. state.isActivity = variable
  140. },
  141. setChangeVar(state, variable) {
  142. state.isIphoneX = variable
  143. },
  144. setIsIphone(state, variable) { // 记录设备信息是否为IphoneX
  145. state.isIphone = variable
  146. },
  147. setLoginType(state, variable) { // 记录登录跳转类型
  148. state.isLoginType = variable
  149. console.log(state.isLoginType)
  150. },
  151. setLoginProductId(state, variable) { // 记录跳转商品ID
  152. state.isLoginProductId = variable
  153. console.log(state.isLoginProductId)
  154. },
  155. setLoginOrderId(state, variable) { // 记录跳转订单ID
  156. state.isLoginOrderId = variable
  157. console.log(state.isLoginOrderId)
  158. }
  159. },
  160. actions: {
  161. setVariableFun: function(context, vData) {
  162. context.commit('setChangeVar', vData)
  163. },
  164. setIsIphoneFun: function(context, vData) {
  165. context.commit('setIsIphone', vData)
  166. },
  167. setActivityFn: function(context, vData) {
  168. context.commit('setActivity', vData)
  169. },
  170. // setLoginTypeFn:function(context,vData){
  171. // context.commit('setLoginType',vData)
  172. // }
  173. }
  174. })
  175. export default store