inform.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { INFORM_TYPE } from '@/EaseIM/constant';
  2. const InformStore = {
  3. state: {
  4. informData: {
  5. contactsInform: [],
  6. groupsInform: [],
  7. },
  8. },
  9. mutations: {
  10. RESET_INFORM_STORE: (state) => {
  11. state.informData = {
  12. contactsInform: [],
  13. groupsInform: [],
  14. };
  15. },
  16. ADD_NEW_INFORM: (state, payload) => {
  17. const { informType, inform } = payload;
  18. inform.time = Date.now();
  19. if (informType === INFORM_TYPE.CONTACTS) {
  20. //此类型通知需要按钮处理
  21. switch (inform.type) {
  22. case 'subscribe':
  23. {
  24. inform.showBtn = true;
  25. inform.handleText = '';
  26. }
  27. break;
  28. case 'unsubscribed':
  29. {
  30. inform.showBtn = false;
  31. inform.handleText = '好友关系已解除';
  32. }
  33. break;
  34. case 'subscribed': {
  35. inform.showBtn = false;
  36. inform.handleText = '好友关系已通过';
  37. }
  38. default:
  39. break;
  40. }
  41. inform.isHandled = false;
  42. state.informData.contactsInform.unshift(inform);
  43. return;
  44. }
  45. if (informType === INFORM_TYPE.GROUPS) {
  46. if (inform.operation === 'inviteToJoin') {
  47. inform.showBtn = true;
  48. inform.handleText = '';
  49. }
  50. inform.isHandled = false;
  51. state.informData.groupsInform.unshift(inform);
  52. return;
  53. }
  54. },
  55. CHANGE_INFORM: (state, payload) => {
  56. const { index, informParams } = payload;
  57. state.informData.contactsInform.splice(index, 1, informParams);
  58. },
  59. READED_INFROM: (state, payload) => {
  60. const { index } = payload;
  61. state.informData.contactsInform[index].isHandled = true;
  62. },
  63. },
  64. actions: {},
  65. getters: {
  66. //获取所有系统通知
  67. getAllInformsList(state) {
  68. let allInforms = [];
  69. allInforms = state.informData.contactsInform.concat(
  70. state.informData.groupsInform
  71. );
  72. return allInforms;
  73. },
  74. },
  75. };
  76. export default InformStore;