index.js 767 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import { mutations } from './mutations'
  4. import { actions } from './actions'
  5. import { initBaseState } from './state'
  6. import chat from './module/chat'
  7. import group from './module/group/index'
  8. Vue.use(Vuex)
  9. const state = initBaseState()
  10. const getters = {
  11. // 判断是否是私聊
  12. isPrivate: state => {
  13. return /-/g.test(state.curSession)
  14. },
  15. // 私聊时候对方的userId
  16. otherUserId: state => {
  17. if (!state.curSession) return
  18. if (state.curSession.indexOf('-') > -1) {
  19. return state.curSession.replace('-', '').replace(state.userId, '')
  20. } else {
  21. return ''
  22. }
  23. }
  24. }
  25. export default new Vuex.Store({
  26. state,
  27. mutations,
  28. actions,
  29. getters,
  30. modules: {
  31. chat,
  32. group
  33. }
  34. })