calendar-control-base.tsx 41.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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
import { Vue, Watch } from 'vue-property-decorator';
import { Subject, Subscription } from 'rxjs';
import dayGridPlugin from '@fullcalendar/daygrid';
import timeGridPlugin from '@fullcalendar/timegrid';
import listPlugin from '@fullcalendar/list';
import interactionPlugin from '@fullcalendar/interaction';
import { Util, ViewTool, ModelTool, LogUtil, throttle, CalendarControlInterface, DataServiceHelp } from 'ibiz-core';
import { MDControlBase } from './md-control-base';
import { AppCalendarService } from '../ctrl-service';
import { ContextMenu } from '../components/common/context-menu/context-menu';
import { AppViewLogicService } from '../app-service';
import { IPSAppDataEntity, IPSDECalendar, IPSDECMUIActionItem, IPSDEContextMenu, IPSDETBUIActionItem, IPSDEToolbar, IPSDEToolbarItem, IPSDEUIAction, IPSSysCalendar, IPSSysCalendarItem } from '@ibiz/dynamic-model-api';
import moment from 'moment';

/**
 * 应用日历部件基类
 *
 * @export
 * @class CalendarControlBase
 * @extends {MDControlBase}
 */
export class CalendarControlBase extends MDControlBase implements CalendarControlInterface {

    /**
     * 日历部件模型实例
     * 
     * @type {IPSDECalendar}
     * @memberof CalendarControlBase
     */
    public declare controlInstance: IPSDECalendar;

    /**
     * 是否初始化完成
     *
     * @type {boolean}
     * @memberof CalendarControlBase
     */
    public inited: boolean = false;

    /**
     * 日历默认打开样式
     * 
     * @type {string}
     * @memberof CalendarControlBase
     */
    public defaultView: string = 'dayGridMonth';

    /**
     * this引用
     *
     * @type {any}
     * @memberof CalendarControlBase
     */
    public thisRef: any = this;

    /**
     * 自定义按钮
     *
     * @type {*}
     * @memberof CalendarControlBase
     */
    public customButtons: any = {};

    /**
     * 引用插件集合
     *
     * @public
     * @type {any[]}
     * @memberof CalendarControlBase
     */
    public calendarPlugins: any[] = [
        dayGridPlugin,
        timeGridPlugin,
        listPlugin,
        interactionPlugin
    ];

    /**
     * 设置头部显示
     *
     * @public
     * @type {}
     * @memberof CalendarControlBase
     */
    public header: any = {
        left: 'prev,next today gotoDate',
        center: 'title',
        right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
    };

    /**
     * 按钮文本集合
     *
     * @public
     * @type {}
     * @memberof CalendarControlBase
     */
    public buttonText: any = {
        today: this.$t('app.calendar.today'),
        month: this.$t('app.calendar.month'),
        week: this.$t('app.calendar.week'),
        day: this.$t('app.calendar.day'),
        list: this.$t('app.calendar.list'),
    };

    /**
     * 模态显示控制变量
     *
     * @public
     * @type boolean
     * @memberof CalendarControlBase
     */
    public modalVisible: boolean = false;

    /**
     * 跳转日期
     *
     * @public
     * @type Date
     * @memberof CalendarControlBase
     */
    public selectedGotoDate: Date = new Date();

    /**
     * 日历部件动态参数
     * 
     * @type {any}
     * @memberof CalendarControlBase
     */
    public ctrlParams: any;

    /**
     * 有效日期范围
     *
     * @public
     * @type {}
     * @memberof CalendarControlBase
     */
    public validRange: any = {
        start: "0000-01-01",
        end: "9999-12-31"
    };

    /**
     * 默认加载日期
     *
     * @public
     * @type {}
     * @memberof CalendarControlBase
     */
    public defaultDate: any = Util.dateFormat(new Date());

    /**
     * 快速工具栏项
     * 
     * @type {Array<any>}
     * @memberof CalendarControlBase
     */
    public quickToolbarItems: Array<any> = [];

    /**
     * 快速工具栏模型
     * 
     * @type {*}
     * @memberof CalendarControlBase
     */
    public quickToolbarModels: any = {};


    /**
     * 日程事件集合
     *
     * @public
     * @type {any[]}
     * @memberof CalendarControlBase
     */
    public events: any[] = [];

    /**
     * 日历项上下文菜单集合
     *
     * @type {string[]}
     * @memberof CalendarControlBase
     */
    public actionModel: any = {
        //TODO待补充
    }

    /**
     * 备份日历项上下文菜单
     *
     * @type {string[]}
     * @memberof CalendarControlBase
     */
    public copyActionModel: any;

    /**
     * 日历样式类型
     *
     * @public
     * @type {string}
     * @memberof CalendarControlBase
     */
    public calendarType: string = '';

    /**
     * 图例显示控制
     *
     * @public
     * @type {any}
     * @memberof CalendarControlBase
     */
    public isShowlegend: any = {};

    /**
     * 是否已经选中第一条数据
     *
     * @type {boolean}
     * @memberof CalendarControlBase
     */
    public isSelectFirst: boolean = false;

    /**
     * 事件id
     *
     * @type {string}
     * @memberof CalendarControlBase
     */
    public eventid: string = "";

    /**
     * 事件类型map
     *
     * @type {any}
     * @memberof CalendarControlBase
     */
    public eventKey: any = new Map();

    /**
     * 查询参数缓存
     *
     * @public
     * @type {any}
     * @memberof CalendarControlBase
     */
    public searchArgCache: any = {};

    /**
     * @description 日历部件事件
     * @type {(Subscription | undefined)}
     * @memberof CalendarControlBase
     */
    public calendarControlEvent: Subscription | undefined;

    /**
     * @description 日历模态事件
     * @type {(Subscription | undefined)}
     * @memberof CalendarControlBase
     */
    public calendarModalEvent: Subscription | undefined;

    /**
     * 监听部件参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof CalendarControlBase
     */
    public onStaticPropsChange(newVal: any, oldVal: any) {
        this.isSelectFirstDefault = newVal.isSelectFirstDefault ? true : false;
        super.onStaticPropsChange(newVal, oldVal)
    }

    /**
     * 部件模型数据初始化
     *
     * @memberof CalendarControlBase
     */
    public async ctrlModelInit(args?: any) {
        await super.ctrlModelInit();
        if (!(this.Environment && this.Environment.isPreviewMode)) {
            this.service = new AppCalendarService(this.controlInstance, this.context);
            this.appEntityService = await DataServiceHelp.getInstance().getService(this.controlInstance?.getPSAppDataEntity(), { context: this.context });
        }
        this.initShowLegend();
        this.initActionModel();
        this.initQuickToolbar();
        this.initEventKey();
        this.calendarType = this.controlInstance?.calendarStyle;
        this.ctrlParams = this.controlInstance?.getPSControlParam()?.ctrlParams;
        this.customButtons = {
            gotoDate: {
                text: this.$t('app.calendar.gotodate'),
                click: this.openDateSelect.bind(this)
            }
        };
        if (Object.is(this.calendarType, 'WEEK')) {
            this.defaultView = 'timeGridWeek';
        } else if (Object.is(this.calendarType, 'DAY')) {
            this.defaultView = 'timeGridDay';
        }
    }

    /**
     * 部件模型数据加载
     *
     * @memberof CalendarControlBase
     */
    public async ctrlModelLoad() {
        const calendarItems = (this.controlInstance as IPSSysCalendar).getPSSysCalendarItems() || [];
        if (calendarItems.length > 0) {
            for (const item of calendarItems) {
                await item.getPSAppDataEntity?.()?.fill?.();
                await item.getNavPSAppView?.()?.fill?.();
            }
        }
    }

    /**
     * 日历视图部件初始化
     *
     * @memberof CalendarControlBase
     */
    public ctrlInit() {
        super.ctrlInit();
        if (!Object.is(this.calendarType, 'TIMELINE')) {
            this.setButtonText();
        }
        if (this.viewState) {
            this.calendarControlEvent = this.viewState.subscribe(({ tag, action, data }: any) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is(action, 'load')) {
                    if (this.inited) {
                        this.refresh();
                    } else {
                        this.inited = true;
                        if (Object.is(this.calendarType, 'TIMELINE')) {
                            this.load();
                        }
                    }
                }
                if (Object.is(action, 'updateSize')) {
                    this.updateSize();
                }
            });
        }
    }

    /**
     * 部件挂载
     *
     * @memberof CalendarControlBase
     */
    public ctrlMounted() {
        super.ctrlMounted();
        this.updateSize();
    }

    /**
     * 初始化日历项上下文菜单集合
     * 
     * @memberof CalendarControlBase
     */
    public initActionModel() {
        const calendarItems: Array<IPSSysCalendarItem> = (this.controlInstance as IPSSysCalendar).getPSSysCalendarItems() || [];
        let tempModel: any = {};
        if (calendarItems.length > 0) {
            calendarItems.forEach((item: IPSSysCalendarItem) => {
                const contextMenuItems: Array<IPSDEToolbarItem> = (item.getPSDEContextMenu() as IPSDEContextMenu)?.getPSDEToolbarItems() || [];
                if (contextMenuItems.length > 0) {
                    contextMenuItems.forEach((toolbarItem: IPSDEToolbarItem) => {
                        this.initActionModelItem(toolbarItem, item, tempModel)
                    })
                }
            })
        }
        this.actionModel = {};
        Object.assign(this.actionModel, tempModel);
    }

    /**
     * 初始化上下菜单项
     * 
     * @param toolbarItem 
     * @param item 
     * @param tempModel 
     * @memberof CalendarControlBase
     */
    public initActionModelItem(toolbarItem: IPSDEToolbarItem, item: IPSSysCalendarItem, tempModel: any) {
        let tempItem: any = {
            name: toolbarItem.name,
            nodeOwner: item.itemType
        }
        if (toolbarItem.itemType == 'DEUIACTION') {
            const uiAction: IPSDEUIAction = (toolbarItem as IPSDECMUIActionItem).getPSUIAction() as IPSDEUIAction;
            if (uiAction) {
                Object.assign(tempItem, {
                    type: item.itemType,
                    tag: uiAction.id,
                    visabled: true,
                    disabled: false,
                    actiontarget: uiAction.actionTarget,
                    noprivdisplaymode: uiAction.noPrivDisplayMode,
                    dataaccaction: uiAction.dataAccessAction
                })
            }
        }
        tempModel[`${item.itemType}_${toolbarItem.name}`] = tempItem;
        //TODO YY 上下文菜单子项
        // if(toolbarItem.getPSDEToolbarItems?.length > 0){
        //     for(let toolBarChild of toolbarItem.getPSDEToolbarItems){
        //         this.initActionModelItem(toolBarChild,item,tempModel)               
        //     }
        // }
    }

    /**
     * 初始化快速工具栏
     *
     * @memberof CalendarControlBase
     */
    public initQuickToolbar() {
        const quickToolbaItems: Array<IPSDEToolbarItem> = (ModelTool.findPSControlByType('QUICKTOOLBAR', this.controlInstance.getPSControls() || []) as IPSDEToolbar)?.getPSDEToolbarItems() || [];
        if (quickToolbaItems.length > 0) {
            let items: Array<any> = quickToolbaItems.filter((item: IPSDEToolbarItem) => {
                return item.itemType == "DEUIACTION";
            });
            this.quickToolbarItems = [...items];
        }
        this.initQuickToolbarItemModel();
    }


    /**
     * 初始化快速工具栏模型
     *
     * @memberof CalendarControlBase
     */
    public initQuickToolbarItemModel() {
        const items: Array<IPSDEToolbarItem> = this.quickToolbarItems;
        let models: any = {};
        if (items.length > 0) {
            items.forEach((_item: IPSDEToolbarItem) => {
                const item: IPSDETBUIActionItem = _item as IPSDETBUIActionItem;
                const uiAction: IPSDEUIAction = item.getPSUIAction() as IPSDEUIAction;
                let model: any = {};
                Object.assign(model, {
                    name: item.name?.toLowerCase(),
                    actiontarget: "NONE",
                    disabled: false,
                    visabled: true,
                    type: item.itemType,
                    noprivdisplaymode: uiAction?.noPrivDisplayMode,
                    dataaccaction: uiAction?.dataAccessAction,
                    uiaction: {
                        tag: uiAction?.uIActionTag ? uiAction.uIActionTag : uiAction.id ? uiAction.id : '',
                        target: uiAction?.actionTarget
                    }
                });
                Object.assign(models, { [`${item.name?.toLowerCase()}`]: model });
            })
        }
        this.quickToolbarModels = {};
        Object.assign(this.quickToolbarModels, models);
    }

    /**
     * 初始化事件map对象
     *
     * @memberof CalendarControlBase
     */
    public initEventKey() {
        const calendarItems: Array<IPSSysCalendarItem> = (this.controlInstance as IPSSysCalendar).getPSSysCalendarItems() || [];
        if (calendarItems.length > 0) {
            calendarItems.forEach((calendarItem) => {
                let eventKey = ModelTool.getAppEntityKeyField(calendarItem?.getPSAppDataEntity())?.codeName?.toLowerCase() || '';
                this.eventKey.set(calendarItem.itemType, eventKey);
            })

        }
    }

    /**
     * 初始化图例显示控制
     * 
     * @memberof CalendarControlBase
     */
    public initShowLegend() {
        if (Object.keys(this.isShowlegend).length > 0) {
            return;
        }
        const calendarItems: Array<IPSSysCalendarItem> = (this.controlInstance as IPSSysCalendar).getPSSysCalendarItems() || [];
        if (calendarItems.length > 0) {
            calendarItems.forEach((item: IPSSysCalendarItem) => {
                this.isShowlegend[item.itemType as string] = true;
            })
        }
    }

    /**
     * 图例点击事件
     *
     * @param {string} itemType 日历项类型
     * @return {*} 
     * @memberof CalendarControlBase
     */
    public legendTrigger(itemType: string) {
        const eventDisabled = this.$el.getElementsByClassName('event-disabled').length;
        if (Object.keys(this.isShowlegend).length != 1 && eventDisabled == Object.keys(this.isShowlegend).length - 1 && this.isShowlegend[itemType]) {
            return;
        }
        this.isShowlegend[itemType] = !this.isShowlegend[itemType];
        this.refresh();
        this.$forceUpdate();
    }

    /**
     * 面板数据变化处理事件
     * @param {any} item 当前数据
     * @param {any} $event 面板事件数据
     *
     * @memberof CalendarControlBase
     */
    public onPanelDataChange(item: any, $event: any) {
        Object.assign(item, $event, { rowDataState: 'update' });
    }

    /**
     * 搜索获取日程事件
     *
     * @param {*} [fetchInfo] 日期信息
     * @param {*} [successCallback] 成功回调
     * @return {*} 
     * @memberof CalendarControlBase
     */
    public load(fetchInfo: any = {}, successCallback?: any) {
        if (this.Environment && this.Environment.isPreviewMode) {
            this.events = [];
            return;
        }
        // 处理请求参数
        let start = (fetchInfo && fetchInfo.start) ? Util.dateFormat(fetchInfo.start) : null;
        let end = (fetchInfo && fetchInfo.end) ? Util.dateFormat(fetchInfo.end) : null;
        let arg = { start: start, end: end };
        if (fetchInfo && fetchInfo.query) {
            Object.assign(arg, { query: fetchInfo.query });
        }
        const parentdata: any = {};
        this.$emit("ctrl-event", { controlname: this.controlInstance?.name, action: "beforeload", data: parentdata });
        Object.assign(arg, parentdata);
        let tempViewParams: any = parentdata.viewparams ? parentdata.viewparams : {};
        Object.assign(tempViewParams, Util.deepCopy(this.viewparams ? this.viewparams : ''));
        Object.assign(arg, { viewparams: tempViewParams });
        // 处理events数据
        let _this = this;
        let handleEvents = () => {
            if (_this.isSelectFirstDefault) {
                _this.isSelectFirst = true;
            }
            let filterEvents = this.events.filter((event: any) => {
                return _this.isShowlegend[event.itemType];
            });
            if (successCallback) {
                successCallback(filterEvents);
            }
            // 刷新日历的大小(仅fullcalendar组件使用)
            if (!Object.is(_this.calendarType, "TIMELINE") && !this.ctrlParams) {
                let appCalendar: any = _this.$refs[this.controlInstance?.codeName];
                let api = appCalendar.getApi();
                if (api) {
                    api.updateSize();
                }
            }
        }
        if (JSON.stringify(arg) === JSON.stringify(this.searchArgCache)) {
            handleEvents();
            return;
        } else {
            this.searchArgCache = arg;
        }
        let tempContext: any = Util.deepCopy(this.context);
        this.handleCtrlEvents('onbeforeload', { action: this.loadAction, navContext: tempContext, navParam: arg }).then((res: boolean) => {
            if (res) {
                this.onControlRequset('load', tempContext, arg);
                const post: Promise<any> = this.service.search(this.loadAction, tempContext, arg, this.showBusyIndicator);
                post.then((response: any) => {
                    this.onControlResponse('load', response);
                    if (!response || response.status !== 200) {
                        this.handleCtrlEvents('onloaderror', { action: this.loadAction, navParam: arg, data: response?.data }).then((res: boolean) => {
                            if (res) {
                                this.$throw(response, 'searchEvents');
                            }
                        })
                    } else {
                        // 默认选中第一项
                        this.events = response.data;
                        this.handleCtrlEvents('onloadsuccess', { action: this.loadAction, navParam: arg, data: this.events }).then((res: boolean) => {
                            if (res) {
                                this.ctrlEvent({
                                    controlname: this.name,
                                    action: 'load',
                                    data: this.events,
                                });
                                handleEvents();
                                this.scheduleSort();
                            }
                        })
                    }
                }, (error: any) => {
                    this.onControlResponse('load', error);
                    this.handleCtrlEvents('onloaderror', { action: this.loadAction, navParam: arg, data: error?.data }).then((res: boolean) => {
                        if (res) {
                            this.$throw(error, 'searchEvents');
                        }
                    })
                });
            }
        })
    }

    /**
     * 日期点击事件
     *
     * @param {*} $event 日期信息
     * @memberof CalendarControlBase
     */
    public onDateClick($event: any) {
        let date = $event.date;
        let datestr = $event.dateStr;
    }

    /**
     * 时间轴点击事件
     * 
     * @param {*} item 项数据
     * @memberof CalendarControlBase
     */
    public onTimeLineClick(item: any) {
        this.events.forEach((event: any) => {
            event.srfchecked = 0;
        })
        item.srfchecked = Number(!item.srfchecked);
        this.onEventClick(item, true);
        this.$forceUpdate();
    }

    /**
     * 处理日历日程选中样式
     * 
     * @param {*} item 项数据
     * @memberof CalendarControlBase
     */
    public handleEventSelectStyle($event: any) {
        const calendarApi: any = (this.$refs[this.controlInstance?.codeName] as any)?.getApi();
        if (!calendarApi) {
            return;
        }
        const findApis = (id: any) => {
            if (!id) {
                return [];
            }
            return calendarApi.getEvents().filter((event: any) => {
                return event.extendedProps.curdata[this.getEventKey(event.extendedProps)] === id;
            });
        }
        const eventId: any = $event.event.extendedProps.curdata[this.getEventKey($event.event.extendedProps)];
        const eventApis: any[] = findApis(eventId);
        eventApis.forEach((api: any) => {
            const classNames: any[] = [...api.classNames];
            if (classNames.findIndex((className: any) => { return className == 'selected-event'; }) === -1) {
                classNames.push('selected-event')
            }
            api.setProp('classNames', classNames);
        })
        if (this.isSelectFirstDefault && this.eventid != eventId || (!this.isSelectFirstDefault)) {
            const _eventApis: any[] = findApis(this.eventid);
            _eventApis.forEach((api: any) => {
                const _temp: any[] = [...api.classNames];
                const index = _temp.findIndex((className: any) => { return className == 'selected-event'; });
                if (index !== -1) {
                    _temp.splice(index, 1);
                    api.setProp('classNames', _temp);
                }
            })
        }
        this.eventid = this.eventid && this.eventid == eventId && !this.isSelectFirstDefault ? '' : eventId;
    }

    /**
     * 日程点击事件
     *
     * @param {*} $event calendar事件对象或event数据
     * @param {*} isOriginData true:$event是原始event数据,false:是组件
     * @param {*} $event timeline事件对象
     * @memberof CalendarControlBase
     */
    public onEventClick($event: any, isOriginData: boolean = false, $event2?: any) {
        this.handleCtrlEvents('onselectionchange', { action: 'SelectionChange', data: $event }).then((res: boolean) => {
            if (!res) {
                return;
            }
            // 处理event数据
            let event: any = {};
            if (isOriginData) {
                event = Util.deepCopy($event);
            } else {
                event = Object.assign({ title: $event.event.title, start: $event.event.start, end: $event.event.end }, $event.event.extendedProps);
            }
            // 点击选中样式
            let JSelement: any = null;
            if (!isOriginData && $event.el) {
                JSelement = $event.el;
            } else if (isOriginData && $event2 && $event2.currentTarget) {
                JSelement = $event2.currentTarget;
            }
            const eventId: any = event.curdata[this.getEventKey(event)];
            let tempItem = this.events.find((_item: any) => { return _item.curdata[this.getEventKey(_item)] == eventId });
            if (this.eventid && this.eventid == eventId) {
                if (tempItem) tempItem.curdata.srfchecked = 0;
            } else {
                if (tempItem) tempItem.curdata.srfchecked = 1;
            }
            this.selections = this.eventid && this.eventid == eventId ? [] : [event];
            this.handleEventSelectStyle($event);
            // 处理上下文数据
            let _this: any = this;
            let view: any = {};
            let _context: any = Object.assign({}, this.context);
            let _viewparams: any = Object.assign({ start: event.start, end: event.end }, this.viewparams);
            const item: IPSSysCalendarItem = (((this.controlInstance as IPSSysCalendar).getPSSysCalendarItems() || []) as Array<IPSSysCalendarItem>).find((_item: IPSSysCalendarItem) => {
                return _item.itemType == event.itemType;
            }) as IPSSysCalendarItem;
            if (item) {
                const codeName = ((item.getPSAppDataEntity() as IPSAppDataEntity)?.codeName as string).toLowerCase();
                if (codeName) {
                    _context[codeName] = event[codeName];
                    view = this.getEditView(codeName);
                }
            }
            // 导航栏中不需要打开视图,只要抛出选中数据
            this.$emit("ctrl-event", { controlname: this.controlInstance.name, action: "selectionchange", data: this.selections });
            if (this.isSelectFirstDefault) {
                return;
            }
            // 根据打开模式打开视图
            if (!view.viewname) {
                return;
            } else if (Object.is(view.placement, 'INDEXVIEWTAB') || Util.isEmpty(view.placement)) {
                const routePath = ViewTool.buildUpRoutePath(_this.$route, this.context, view.deResParameters, view.parameters, [Util.deepCopy(_context)], _viewparams);
                _this.$router.push(routePath);
            } else {
                let container: Subject<any> = new Subject();
                if (Object.is(view.placement, 'POPOVER')) {
                    container = _this.$apppopover.openPop(isOriginData ? $event2 : $event.jsEvent, view, Util.deepCopy(_context), _viewparams);
                } else if (Object.is(view.placement, 'POPUPMODAL')) {
                    container = _this.$appmodal.openModal(view, Util.deepCopy(_context), _viewparams);
                } else if (view.placement.startsWith('DRAWER')) {
                    container = _this.$appdrawer.openDrawer(view, Util.getViewProps(_context, _viewparams));
                }
                this.calendarModalEvent = container.subscribe((result: any) => {
                    if (!result || !Object.is(result.ret, 'OK')) {
                        return;
                    }
                    // 刷新日历
                    _this.refresh();
                });
            }
        });
    }

    /**
     * 日历刷新
     *
     * @param {*} [args] 额外参数
     * @memberof CalendarControlBase
     */
    public refresh(args?: any) {
        if (Object.is(this.calendarType, 'TIMELINE')) {
            this.searchArgCache = {}
            this.load();
        } else if (this.ctrlParams) {
            let calendarTimeLine: any = this.$refs['appCalendarTimeline'];
            if (calendarTimeLine) {
                calendarTimeLine.refetchEvents();
            }
        } else {
            let calendarApi = (this.$refs[this.controlInstance?.codeName] as any).getApi();
            calendarApi.refetchEvents();
        }
    }

    /**
     * 日程拖动事件
     *
     * @param {*} $event 事件信息
     * @memberof CalendarControlBase
     */
    public onEventDrop($event: any) {
        if (this.isSelectFirstDefault) {
            return;
        }
        let arg: any = {};
        let _context: any = Object.assign({}, this.context);
        arg.start = Util.dateFormat($event.event.start);
        arg.end = Util.dateFormat($event.event.end);
        let itemType = $event.event._def.extendedProps.itemType;
        const item: IPSSysCalendarItem = (((this.controlInstance as IPSSysCalendar).getPSSysCalendarItems() || []) as Array<IPSSysCalendarItem>).find((_item: IPSSysCalendarItem) => {
            return _item.itemType == itemType;
        }) as IPSSysCalendarItem;
        if (item) {
            const codeName = ((item.getPSAppDataEntity() as IPSAppDataEntity)?.codeName as string).toLowerCase();
            if (codeName) {
                arg[codeName] = $event.event._def.extendedProps[codeName];
                _context[codeName] = $event.event._def.extendedProps[codeName];
            }
        }
        Object.assign(arg, { viewparams: this.viewparams });
        let tempContext: any = Util.deepCopy(this.context);
        this.handleCtrlEvents('onbeforedrop', { action: itemType, navContext: tempContext, navParam: arg }).then((res: boolean) => {
            if (res) {
                this.onControlRequset('onEventDrop', tempContext, arg);
                const post: Promise<any> = this.service.update(itemType, tempContext, arg, this.showBusyIndicator);
                post.then((response: any) => {
                    this.onControlResponse('onEventDrop', response);
                    if (!response || response.status !== 200) {
                        this.handleCtrlEvents('ondroperror', { action: itemType, navParam: arg, data: response?.data }).then((res: boolean) => {
                            if (res) {
                                this.$throw(response, 'onEventDrop');
                            }
                        })
                    } else {
                        this.handleCtrlEvents('ondropsuccess', { action: itemType, navParam: arg, data: response?.data }).then((res: boolean) => {
                            if (res) {
                                // TODO
                            }
                        })
                    }
                }, (response: any) => {
                    this.onControlResponse('onEventDrop', response);
                    this.handleCtrlEvents('ondroperror', { action: itemType, navParam: arg, data: response?.data }).then((res: boolean) => {
                        if (res) {
                            this.$throw(response, 'onEventDrop');
                        }
                    })
                });
            }
        })
    }

    /**
     * 快速工具栏菜单项点击
     * 
     * @param {*} tag 菜单项标识
     * @param {*} $event 事件源
     * @memberof CalendarControlBase
     */
    public itemClick(tag: any, $event: any) {
        AppViewLogicService.getInstance().executeViewLogic(`calendar_quicktoolbar_${tag}_click`, $event, this, {}, this.controlInstance.getPSAppViewLogics() || []);
    }

    /**
     * 时间点击
     *
     * @param {*} $event 当前时间
     * @param {*} jsEvent 原生事件对象  
     * @returns
     * @memberof CalendarControlBase
     */
    public onDayClick($event: any, jsEvent: any) {
        let _this: any = this;
        let content: any = this.renderBarMenu;
        const container: any = _this.$apppopover.openPopover(jsEvent, content, "left-end", true, 103, _this.quickToolbarItems.length * 34);
    }

    /**
     * 计算节点右键权限
     *
     * @param {*} data 日历项数据
     * @param {*} appEntityName 应用实体名称  
     * @returns
     * @memberof CalendarControlBase
     */
    public async computeNodeState(data: any, appEntity: IPSAppDataEntity) {
        let service = await DataServiceHelp.getInstance().getService(appEntity, { context: this.context });
        if (this.copyActionModel && Object.keys(this.copyActionModel).length > 0) {
            if (service) {
                let tempContext: any = Util.deepCopy(this.context);
                tempContext[appEntity.codeName.toLowerCase()] = data[appEntity.codeName.toLowerCase()];
                let targetData = await service.execute('Get', tempContext, {});
                ViewTool.calcTreeActionItemAuthState(targetData.data, this.copyActionModel, this.appUIService);
                return this.copyActionModel;
            } else {
                LogUtil.warn(this.$t('app.warn.geterror'));
                return this.copyActionModel;
            }
        }
        return this.copyActionModel;
    }

    /**
     * 计算日历日程样式
     * 
     * @param info 
     */
    public handleEventStyle(info?: any) {
        if (!info) {
            return;
        }
        const calendarApi: any = (this.$refs[this.controlInstance?.codeName] as any)?.getApi();
        if (!calendarApi) {
            return;
        }
        const data = info.event.extendedProps.curdata;
        let calendarItem: IPSSysCalendarItem = (((this.controlInstance as IPSSysCalendar).getPSSysCalendarItems() || []) as Array<IPSSysCalendarItem>).find((_item: IPSSysCalendarItem) => {
            return _item.itemType == data.itemType;
        }) as IPSSysCalendarItem;
        const cssName = calendarItem?.getPSSysCss?.()?.cssName;
        const calendarEvents: any[] = calendarApi.getEvents().filter((event: any) => {
            return event.extendedProps.curdata[this.getEventKey(event.extendedProps)] === data[this.getEventKey(info.event.extendedProps)];
        });
        if (cssName && calendarEvents.length > 0) {
            calendarEvents.forEach((event: any) => {
                const classNames: any[] = [...event.classNames];
                if (classNames.findIndex((className: any) => { return className == cssName; }) === -1) {
                    classNames.push(cssName);
                    event.setProp('classNames', classNames);
                }
            })
        }
    }

    /**
     * 事件绘制回调
     *
     * @param {*} info 信息
     * @memberof CalendarControlBase
     */
    public eventRender(info?: any,) {
        if (this.isSelectFirstDefault && this.isSelectFirst) {
            this.isSelectFirst = false;
            this.onEventClick(info);
        }
        this.handleEventStyle(info);
        let data = Object.assign({ title: info.event.title, start: info.event.start, end: info.event.end }, info.event.extendedProps);
        info.el.addEventListener('contextmenu', (event: MouseEvent) => {
            this.copyActionModel = {};
            Object.values(this.actionModel).forEach((item: any) => {
                if (Object.is(item.nodeOwner, data.itemType)) {
                    this.copyActionModel[item.name] = item;
                }
            })
            if (Object.keys(this.copyActionModel).length === 0) {
                return;
            }
            let dataMapping: IPSSysCalendarItem = (((this.controlInstance as IPSSysCalendar).getPSSysCalendarItems() || []) as Array<IPSSysCalendarItem>).find((_item: IPSSysCalendarItem) => {
                return _item.itemType == data.itemType;
            }) as IPSSysCalendarItem;
            const appDECodeName = (dataMapping.getPSAppDataEntity() as IPSAppDataEntity)?.codeName as string;
            if (!appDECodeName) {
                return;
            }
            this.computeNodeState(data, (dataMapping.getPSAppDataEntity() as IPSAppDataEntity)).then((result: any) => {
                let flag: boolean = false;
                if (Object.values(result).length > 0) {
                    flag = Object.values(result).some((item: any) => {
                        return item.visabled === true;
                    })
                }
                if (flag) {
                    let props = { data: data, renderContent: this.renderContextMenu };
                    let component = ContextMenu;
                    const vm: any = new Vue({
                        render(h) {
                            return h(component, { props });
                        }
                    }).$mount();
                    document.body.appendChild(vm.$el);
                    const comp: any = vm.$children[0];
                    comp.showContextMenu(event.clientX, event.clientY);
                }
            });
        });
    }

    /**
     * 绘制右键菜单
     *
     * @param {*} event
     * @returns
     * @memberof CalendarControlBase
     */
    public renderContextMenu(event: any) {
        if (!event || !event.itemType) {
            return null;
        }
        this.selections = [event];
        const calendarItems: Array<IPSSysCalendarItem> = (this.controlInstance as IPSSysCalendar).getPSSysCalendarItems() || [];
        if (calendarItems.length > 0) {
            let item: IPSSysCalendarItem = calendarItems.find((_item: IPSSysCalendarItem) => {
                return _item.itemType == event.itemType;
            }) as IPSSysCalendarItem;
            const contextMenu = item.getPSDEContextMenu() as IPSDEContextMenu;
            if (contextMenu && contextMenu.controlType == "CONTEXTMENU") {
                let { targetCtrlName, targetCtrlParam, targetCtrlEvent }: { targetCtrlName: string, targetCtrlParam: any, targetCtrlEvent: any } = this.computeTargetCtrlData(contextMenu, event);
                targetCtrlParam.dynamicProps.contextMenuActionModel = this.copyActionModel;
                return this.$createElement(targetCtrlName, { props: targetCtrlParam, ref: contextMenu.name, on: targetCtrlEvent });
            }
        }
        return null;
    }

    /**
     * 绘制快速工具栏项
     * 
     * @returns
     * @memberof CalendarControlBase
     */
    public renderBarMenu() {
        return (
            <div class="calendar-popover">
                <dropdown
                    class="quick-toolbar"
                    trigger="custom"
                    visible={true}
                    on-on-click={($event: any, $event2: any) => throttle(this.itemClick, [$event, $event2], this)}>
                    <dropdown-menu slot="list">
                        {this.quickToolbarItems.map((item: any) => {
                            return (
                                <dropdown-item
                                    name={item.name}
                                    v-show={this.quickToolbarModels[item.name].visabled}
                                    disabled={this.quickToolbarModels[item.name].disabled}>
                                    {item.showIcon && item.getPSSysImage ?
                                        <i class={item.getPSSysImage?.cssClass}></i> : null}
                                    {item.showCaption ?
                                        <span title={item.tooltip}>{item.caption}</span> : null}
                                </dropdown-item>
                            );
                        })}
                    </dropdown-menu>
                </dropdown>
            </div>
        );
    }

    /**
     * 部件事件
     * @param ctrl 部件 
     * @param action  行为
     * @param data 数据
     * 
     * @memberof CalendarControlBase
     */
    public onCtrlEvent(controlname: string, action: string, data: any) {
        if (action == 'contextMenuItemClick') {
            AppViewLogicService.getInstance().executeViewLogic(`${controlname}_${data?.data}_click`, undefined, this, {}, this.controlInstance?.getPSAppViewLogics() || []);
        } else if (action == 'panelDataChange') {
            this.onPanelDataChange(data.item, data.data);
        } else {
            this.ctrlEvent({ controlname, action, data });
        }
    }

    /**
     * 设置按钮文本
     *
     * @public
     * @memberof CalendarControlBase
     */
    public setButtonText() {
        this.buttonText.today = this.$t('app.calendar.today');
        this.buttonText.month = this.$t('app.calendar.month');
        this.buttonText.week = this.$t('app.calendar.week');
        this.buttonText.day = this.$t('app.calendar.day');
        this.buttonText.list = this.$t('app.calendar.list');
        this.customButtons.gotoDate.text = this.$t('app.calendar.gotodate');
    }

    /**
     * 监听语言变化
     *
     * @public
     * @memberof CalendarControlBase
     */
    @Watch('$i18n.locale')
    public onLocaleChange(newval: any, val: any) {
        this.setButtonText();
    }

    /**
     * 打开时间选择模态
     *
     * @public
     * @memberof CalendarControlBase
     */
    public openDateSelect() {
        this.modalVisible = true;
    }

    /**
     * 跳转到指定时间
     *
     * @public
     * @memberof CalendarControlBase
     */
    public gotoDate() {
        let appCalendar: any = this.$refs[this.controlInstance?.codeName];
        let api = appCalendar?.getApi();
        if (api) {
            api.gotoDate(this.selectedGotoDate);
        }
    }

    /**
     * 获取事件key
     *
     * @param {*} event 事件对象
     * @return {*} 
     * @memberof CalendarControlBase
     */
    public getEventKey(event: any) {
        if (event?.itemType && this.eventKey.has(event.itemType)) {
            return this.eventKey.get(event.itemType)
        }
        return "";
    }

    /**
     * 获取编辑视图信息
     *
     * @param {string} deName 视图名称
     * @return {*} 
     * @memberof CalendarControlBase
     */
    public getEditView(deName: string) {
        let view: any = {};
        //TODO
        return view;
    }

    /**
     * 重置日历尺寸
     *
     * @memberof CalendarControlBase
     */
    public updateSize() {
        const calendar: any = this.$refs[this.controlInstance?.codeName];
        if (calendar) {
            const api = calendar.getApi();
            api.updateSize()
        }
    }

    /**
     * 计算部件所需参数
     *
     * @param {*} controlInstance 部件模型对象
     * @param {*} item 日历项数据
     * @returns
     * @memberof CalendarControlBase
     */
    public computeTargetCtrlData(controlInstance: any, item?: any) {
        const { targetCtrlName, targetCtrlParam, targetCtrlEvent } = super.computeTargetCtrlData(controlInstance);
        Object.assign(targetCtrlParam.dynamicProps, {
            navdatas: [item?.curdata],
        })
        Object.assign(targetCtrlParam.staticProps, {
            transformData: this.transformData,
            opendata: this.opendata,
            newdata: this.newdata,
            refresh: this.refresh,
        })
        targetCtrlEvent['ctrl-event'] = ({ controlname, action, data }: { controlname: string, action: string, data: any }) => {
            this.onCtrlEvent(controlname, action, { item: item.curdata, data: data });
        };
        return { targetCtrlName, targetCtrlParam, targetCtrlEvent };
    }

    /**
     * 日程排序
     * 
     * @memberof CalendarControlBase
     */
    public scheduleSort() {
        if (Object.is(this.calendarType, 'TIMELINE') && this.events.length > 0) {
            this.events.sort((a: any, b: any) => {
                const x: any = a.start;
                const y: any = b.start;
                return moment(x).isAfter(y) ? -1 : moment(x).isBefore(y) ? 1 : 0;
            })
            // 默认选中第一项
            if (this.isSelectFirstDefault) {
                this.onTimeLineClick(this.events[0]);
            }
        }
    }

    /**
     * @description 部件销毁
     * @memberof CalendarControlBase
     */
    public ctrlDestroyed() {
        super.ctrlDestroyed();
        if (this.calendarControlEvent) {
            this.calendarControlEvent.unsubscribe();
        }
        if (this.calendarModalEvent) {
            this.calendarModalEvent.unsubscribe();
        }
    }
}