PropertyDescription.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import _ from 'lodash'
  2. export type GroupType = 'css' | 'data' | 'bind' | 'common' | 'event'
  3. export interface PropertyValue {
  4. /**
  5. * 属性名
  6. */
  7. name: string
  8. /**
  9. * 默认值
  10. */
  11. default: any
  12. /**
  13. * 隶属分组
  14. */
  15. group: GroupType
  16. /**
  17. * 描述
  18. */
  19. desc: string
  20. /**
  21. * 取值范围
  22. */
  23. type:
  24. | 'boolean'
  25. | 'number'
  26. | 'string'
  27. | 'object'
  28. | 'dataSource'
  29. | 'valid'
  30. | 'format'
  31. | Array<string>
  32. | 'widget'
  33. eventParamter?: string[]
  34. eventResult?: string
  35. eventDoc?:(vjson:any)=>string
  36. expr?: boolean,
  37. }
  38. export interface EventValue {
  39. /**
  40. * 属性名
  41. */
  42. name: string
  43. /**
  44. * 描述
  45. */
  46. desc: string
  47. }
  48. export interface PropertyDescriptionInterface {
  49. props: PropertyValue[]
  50. events?: EventValue[]
  51. }
  52. export class PropertyDescription {
  53. propertyes: PropertyDescriptionInterface = {
  54. props: [],
  55. events: []
  56. }
  57. constructor(...args: PropertyDescriptionInterface[]) {
  58. _.each(args, arg => {
  59. this.merge(arg)
  60. })
  61. }
  62. merge(pd: PropertyDescriptionInterface) {
  63. this.propertyes.props = <any>(
  64. _.uniqBy([...this.propertyes.props, ...pd.props], 'name')
  65. )
  66. if (pd.events) {
  67. if (this.propertyes.events) {
  68. this.propertyes.events = <any>(
  69. _.uniqBy([...this.propertyes.events, ...pd.events], 'name')
  70. )
  71. } else {
  72. this.propertyes.events = <any>_.uniqBy([...pd.events], 'name')
  73. }
  74. }
  75. }
  76. /**
  77. * 根据分组名 获取属性定义
  78. */
  79. getPropsByGroup(name: GroupType): PropertyValue[] {
  80. return _.filter(this.propertyes.props, i => i.group === name)
  81. }
  82. /**
  83. * 获取全部事件
  84. */
  85. getEvents(): EventValue[] {
  86. return this.propertyes.events!
  87. }
  88. }