设计模式实践

策略模式 #

 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
class D {
    createCode(parentId, followTaskId): string {
        const parent = this.getTaskById(parentId);
        let code = '';
        if (parent) {
            const parentCode = parent.taskNbr;
            if (followTaskId) {
                code = `${parentCode}${parentCode ? '.' : ''}${nbrArr.length ? Number(nbrArr[nbrArr.length - 1]) + 1 : ''}`;
            } else {
                code = `${parentCode}${parentCode ? '.' : ''}${children.length + 1}`;
            }
        } else {
            code = `${index + 2}`;
        }
        return code;
    }

    public createTaskResolver(data, mode) {
        const task: any = {};
        const parentId = String(data.parentId ? data.parentId : '')
        if (parentId) {
            task.parent = {id: parentId}
        }
        if (data && data.followTaskIndex >= 0) {
            task.followTaskIndex = data.followTaskIndex;
        }
        return task
    }

    public setCreatePullData(task: IProjectTask) {
        let topLevel = this.getTopLevelTasks();
        if (!oc(task.parent).id('')) {
        } else {
        }
        if (task.followTaskId && !task[F_ProjectTask_scheduledStart]) {
        }
        return toJS(task);
    }

    public getFollowTaskId(data, allData): string {
        if (data.followTaskId) {
        } else if (data.parentId) {
        }
    }
}

xx模式 #

 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
class E {
    private showDialog = (
        mode: BizFormModeEnum,
        dataId: string,
        options: Optional<IBizFormDialogOptions> = {},
    ) => {
        // 如果dialogId存在,说明弹窗已经生成,那么就先关闭那个弹窗,防止多次点击出现多个弹窗
        if (this.mediator.dialogId) this.mediator.closeTaskDialog();

        this.presenter.getBean(PageBeanNames.NestFormController).showNestBizFormDialog(
            {
                fieldName: F_ProjectSchedule_tasks,
            },
            {
                title: '任务详情',
                size: 'largest',
                dataId: dataId,
                mode: mode,
                options: {
                    ...options,
                    projectScheduleAPI: this.presenter.options.projectScheduleAPI,
                    displayOptions: {
                        suppressDetailAttachmentUpload: [F_ProjectTask_deliverables]
                    },
                    onSave: (dialogOptions) => {
                        setTimeout(() => {
                            this.updateGanttData(true, dialogOptions.dataId, dialogOptions.options.taskContext.followTaskIndex);
                        }, 300);
                    }
                },
                customizeButtons: options.customizeButtons,
                presenterClass: TaskFormPresenter,
                presenterOptions: {
                    passParams: {
                        // showDialog: this.showDialog,
                        mediatorKey: this.mediatorKey,
                        passOptions: {
                            mainPresenterAttachment: (task, newFiles) => {
                                this.setTaskAttachmentAppendRow(task, newFiles);
                            },
                            mainPresenterSave: () => {
                                this.presenter.api.save()
                            },
                            mainPresenterIsEdit: () => {
                                return this.presenter.api.stateController.isEditing;
                            }
                        }
                    },
                },
            }
        )
    }
}

showNestBizFormDialog的参数是一个大型的option,而此方法中用到了其中一部分参数

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
interface NestBizFormDialogOption {
    nestFieldName?: string,
    title: string,
    size: string,
    dataId: string,
    mode: string,
    suppressDetailAttachmentUpload: [F_ProjectTask_deliverables],
    onSave: () => void,
    customizeButtons,
    mediatorKey,
    mainPresenterAttachment: (task, newFiles) => void,
    mainPresenterSave: () => void,
    mainPresenterIsEdit: () => void,
}