groupStore.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {defineStore} from "pinia";
  2. import type Group from "@/mode/Group";
  3. import GroupApi from "@/api/GroupApi";
  4. // @ts-ignore
  5. import Tools from "@/utils/Tools";
  6. import GroupInviteApi from "@/api/GroupInviteApi";
  7. export interface IState {
  8. groupList: Array<Group>;
  9. waitCheckMap: Map<string, number>;
  10. groupIndexMap: Map<string, Object>;
  11. }
  12. export const useGroupStore = defineStore({
  13. id: "group_store",
  14. state: (): IState => ({
  15. groupList: [],
  16. waitCheckMap: new Map<string, number>(),
  17. groupIndexMap: new Map<string, Object>()
  18. }),
  19. getters: {
  20. getGroupById: (state) => (id: string) => {
  21. return state.groupIndexMap.get(id);
  22. },
  23. getGroupList(): Array<Group> {
  24. return this.groupList;
  25. },
  26. },
  27. actions: {
  28. setGroupList(groupList: Array<Group>): Array<Group> {
  29. return (this.groupList = groupList);
  30. },
  31. loadWaitCheckList() {
  32. this.waitCheckMap = new Map<string, number>();
  33. GroupInviteApi.waitCheckList().then(res => {
  34. res.data.forEach((value: any) => {
  35. this.waitCheckMap.set(value.groupId, value.count);
  36. })
  37. });
  38. },
  39. loadGroupList() {
  40. GroupApi.list().then(res => {
  41. this.groupList = res.data
  42. this.groupIndexMap = Tools.listToMap(res.data);
  43. })
  44. },
  45. },
  46. });