confProxy.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. export default class ConfProxy<T> {
  2. static getKey(args: string[]): string {
  3. let out = ""
  4. args.forEach(element => {
  5. out += element
  6. out += "_"
  7. });
  8. return out
  9. }
  10. static setKey(target: any, args: string[]): string {
  11. let out = ""
  12. args.forEach(element => {
  13. out += target[element]
  14. out += "_"
  15. });
  16. return out
  17. }
  18. pool: { [key: string]: T } = {}
  19. name:string = ""
  20. constructor(xlsname:string,conf: T[], ...args: string[]) {
  21. this.name = xlsname
  22. conf.forEach(element => {
  23. this.pool[ConfProxy.setKey(element, args)] = element
  24. });
  25. }
  26. getItem(...args: string[]): T | null {
  27. return this.pool[ConfProxy.getKey(args)]
  28. }
  29. }
  30. export class ConfListProxy<T> {
  31. pool: { [key: string]: T[] } = {}
  32. name:string = ""
  33. constructor(xlsname:string,conf: T[], ...args: string[]) {
  34. this.name = xlsname
  35. conf.forEach(element => {
  36. let key = ConfProxy.setKey(element, args)
  37. if (this.pool[key] == null) {
  38. this.pool[key] = []
  39. }
  40. this.pool[key].push(element)
  41. });
  42. }
  43. getItemList(...args: string[]): T[] | null {
  44. return this.pool[ConfProxy.getKey(args)]
  45. }
  46. }