123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import _ from 'lodash'
- export type GroupType = 'css' | 'data' | 'bind' | 'common' | 'event'
- export interface PropertyValue {
- /**
- * 属性名
- */
- name: string
- /**
- * 默认值
- */
- default: any
- /**
- * 隶属分组
- */
- group: GroupType
- /**
- * 描述
- */
- desc: string
- /**
- * 取值范围
- */
- type:
- | 'boolean'
- | 'number'
- | 'string'
- | 'object'
- | 'dataSource'
- | 'valid'
- | 'format'
- | Array<string>
- | 'widget'
- eventParamter?: string[]
- eventResult?: string
- eventDoc?:(vjson:any)=>string
- expr?: boolean,
- }
- export interface EventValue {
- /**
- * 属性名
- */
- name: string
- /**
- * 描述
- */
- desc: string
- }
- export interface PropertyDescriptionInterface {
- props: PropertyValue[]
- events?: EventValue[]
- }
- export class PropertyDescription {
- propertyes: PropertyDescriptionInterface = {
- props: [],
- events: []
- }
- constructor(...args: PropertyDescriptionInterface[]) {
- _.each(args, arg => {
- this.merge(arg)
- })
- }
- merge(pd: PropertyDescriptionInterface) {
- this.propertyes.props = <any>(
- _.uniqBy([...this.propertyes.props, ...pd.props], 'name')
- )
- if (pd.events) {
- if (this.propertyes.events) {
- this.propertyes.events = <any>(
- _.uniqBy([...this.propertyes.events, ...pd.events], 'name')
- )
- } else {
- this.propertyes.events = <any>_.uniqBy([...pd.events], 'name')
- }
- }
- }
- /**
- * 根据分组名 获取属性定义
- */
- getPropsByGroup(name: GroupType): PropertyValue[] {
- return _.filter(this.propertyes.props, i => i.group === name)
- }
- /**
- * 获取全部事件
- */
- getEvents(): EventValue[] {
- return this.propertyes.events!
- }
- }
|