status.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { FeedbackStatusEnum } from "@/enums";
  2. const CacheMap: Record<string, Record<string, any>> = {};
  3. class FeedBackStatus {
  4. current: number = 0;
  5. waitList: string[] = [];
  6. status: FeedbackStatusEnum = FeedbackStatusEnum.NONE;
  7. set(module: string, key: string, value: any) {
  8. if (!CacheMap[module]) {
  9. CacheMap[module] = {};
  10. }
  11. CacheMap[module][key] = value;
  12. this.status = FeedbackStatusEnum.RUNNING;
  13. }
  14. get(module: string, key: string) {
  15. if (!CacheMap[module]) {
  16. return null;
  17. }
  18. return CacheMap[module][key];
  19. }
  20. removeKey(module: string, key: string) {
  21. this.status = FeedbackStatusEnum.NONE;
  22. if (!CacheMap[module]) {
  23. return;
  24. }
  25. delete CacheMap[module][key];
  26. }
  27. removeModule(module: string) {
  28. if (!CacheMap[module]) {
  29. return;
  30. }
  31. delete CacheMap[module];
  32. }
  33. getAll() {
  34. return CacheMap;
  35. }
  36. getStatus() {
  37. return this.status;
  38. }
  39. setStatus(status: FeedbackStatusEnum) {
  40. this.status = status;
  41. }
  42. }
  43. const feedbackStatus = new FeedBackStatus();
  44. export default feedbackStatus;