app-calendar-model.ts 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
import { IPSAppDataEntity, IPSAppDEField, IPSDECalendar, IPSSysCalendar, IPSSysCalendarItem } from '@ibiz/dynamic-model-api';
import { ModelTool } from 'ibiz-core';

export class AppCalendarModel {

    /**
    * 日历实例对象
    *
    * @memberof AppCalendarModel
    */
    public calendarInstance !: IPSDECalendar;

    /**
     * 日历项类型
     *
     * @returns {string}
     * @memberof AppCalendarModel
     */
    public itemType: string = '';

    /**
    * Creates an instance of AppCalendarModel.
    * 
    * @param {*} [opts={}]
    * @memberof AppCalendarModel
    */
    constructor(opts: any) {
        this.calendarInstance = opts;
    }

    public getDataItems(): any[] {
        let modelArray: any[] = [
            // 前端新增修改标识,新增为"0",修改为"1"或未设值
            {
                name: 'srffrontuf',
                prop: 'srffrontuf',
                dataType: 'TEXT',
            },
            {
                name: 'color',
            },
            {
                name: 'textColor',
            },
            {
                name: 'curdata',
            },
            {
                name: 'itemType',
            },
            {
                name: 'query',
                prop: 'query',
            },
        ];
        if (!this.itemType) {
            return modelArray;
        }
        //日历项实体映射
        const calendarItems: Array<IPSSysCalendarItem> = (this.calendarInstance as IPSSysCalendar).getPSSysCalendarItems() || [];
        const item: IPSSysCalendarItem = calendarItems?.find((_item: IPSSysCalendarItem) => {
            return _item.itemType == this.itemType;
        }) as IPSSysCalendarItem;
        if (item) {
            const entity = item.getPSAppDataEntity() as IPSAppDataEntity;
            const idField: IPSAppDEField = item.getIdPSAppDEField() as IPSAppDEField;
            const beginField: IPSAppDEField = item.getBeginTimePSAppDEField() as IPSAppDEField;
            const endField: IPSAppDEField = item.getEndTimePSAppDEField() as IPSAppDEField;
            const textField: IPSAppDEField = item.getTextPSAppDEField() as IPSAppDEField;
            const bKColorField: IPSAppDEField = item.getBKColorPSAppDEField() as IPSAppDEField;
            const colorField: IPSAppDEField = item.getColorPSAppDEField() as IPSAppDEField;
            const contentField: IPSAppDEField = item.getContentPSAppDEField() as IPSAppDEField;
            let tempArr: any[] = [{
                name: entity?.codeName?.toLowerCase(),
                prop: idField?.codeName ? idField.codeName.toLowerCase()
                    : ((ModelTool.getAppEntityKeyField(entity) as IPSAppDEField)?.codeName || '').toLowerCase()
            }, {
                name: 'title',
                prop: textField?.codeName ? textField.codeName.toLowerCase()
                    : ((ModelTool.getAppEntityKeyField(entity) as IPSAppDEField)?.codeName || '').toLowerCase()
            }, {
                name: 'start',
                prop: beginField?.codeName ? beginField.codeName.toLowerCase() : beginField?.name?.toLowerCase()
            }, {
                name: 'end',
                prop: endField?.codeName ? endField.codeName.toLowerCase() : endField?.name?.toLowerCase()
            }, {
                name: 'bkcolor',
                prop: bKColorField?.codeName ? bKColorField.codeName.toLowerCase() : bKColorField?.name?.toLowerCase()
            }, {
                name: 'color',
                prop: colorField?.codeName ? colorField.codeName.toLowerCase() : colorField?.name?.toLowerCase()
            }];
            if (contentField) {
                tempArr.push({
                    name: 'content',
                    prop: contentField?.codeName ? contentField.codeName.toLowerCase() : contentField?.name?.toLowerCase()
                })
            }
            modelArray = [...modelArray, ...tempArr];
        }
        return modelArray;
    }
}