Amy0104
3 years ago
committed by
GitHub
32 changed files with 886 additions and 140 deletions
@ -0,0 +1,136 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
import { ref, watch } from 'vue' |
||||
import { useI18n } from 'vue-i18n' |
||||
import { useRelationCustomParams, useTimeoutAlarm } from '.' |
||||
import type { IJsonItem } from '../types' |
||||
|
||||
export function useConditions(model: { [field: string]: any }): IJsonItem[] { |
||||
const { t } = useI18n() |
||||
|
||||
const taskCodeOptions = ref([] as { label: string; value: number }[]) |
||||
const postTasksOptions = ref([] as { label: string; value: number }[]) |
||||
const stateOptions = [ |
||||
{ label: t('project.node.success'), value: 'success' }, |
||||
{ label: t('project.node.failed'), value: 'failed' } |
||||
] |
||||
|
||||
watch( |
||||
() => model.preTasks, |
||||
() => { |
||||
taskCodeOptions.value = |
||||
model.preTaskOptions |
||||
?.filter((task: { code: number }) => |
||||
model.preTasks?.includes(task.code) |
||||
) |
||||
.map((task: { code: number; name: string }) => ({ |
||||
value: task.code, |
||||
label: task.name |
||||
})) || [] |
||||
} |
||||
) |
||||
|
||||
watch( |
||||
() => model.postTaskOptions, |
||||
() => { |
||||
postTasksOptions.value = model.postTasksOptions.map( |
||||
(task: { code: number; name: string }) => ({ |
||||
value: task.code, |
||||
label: task.name |
||||
}) |
||||
) |
||||
} |
||||
) |
||||
|
||||
return [ |
||||
{ |
||||
type: 'select', |
||||
field: 'successNode', |
||||
name: t('project.node.state'), |
||||
span: 12, |
||||
props: { |
||||
disabled: true |
||||
}, |
||||
options: stateOptions |
||||
}, |
||||
{ |
||||
type: 'select', |
||||
field: 'successBranch', |
||||
name: t('project.node.branch_flow'), |
||||
span: 12, |
||||
props: { |
||||
clearable: true |
||||
}, |
||||
options: postTasksOptions |
||||
}, |
||||
{ |
||||
type: 'select', |
||||
field: 'failedNode', |
||||
name: t('project.node.state'), |
||||
span: 12, |
||||
props: { |
||||
disabled: true |
||||
}, |
||||
options: stateOptions |
||||
}, |
||||
{ |
||||
type: 'select', |
||||
field: 'failedBranch', |
||||
name: t('project.node.branch_flow'), |
||||
span: 12, |
||||
props: { |
||||
clearable: true |
||||
}, |
||||
options: postTasksOptions |
||||
}, |
||||
...useTimeoutAlarm(model), |
||||
...useRelationCustomParams({ |
||||
model, |
||||
children: { |
||||
type: 'custom-parameters', |
||||
field: 'dependItemList', |
||||
span: 18, |
||||
children: [ |
||||
{ |
||||
type: 'select', |
||||
field: 'depTaskCode', |
||||
span: 10, |
||||
options: taskCodeOptions |
||||
}, |
||||
{ |
||||
type: 'select', |
||||
field: 'status', |
||||
span: 10, |
||||
options: [ |
||||
{ |
||||
value: 'SUCCESS', |
||||
label: t('project.node.success') |
||||
}, |
||||
{ |
||||
value: 'FAILURE', |
||||
label: t('project.node.failed') |
||||
} |
||||
] |
||||
} |
||||
] |
||||
}, |
||||
childrenField: 'dependItemList', |
||||
name: 'custom_parameters' |
||||
}) |
||||
] |
||||
} |
@ -0,0 +1,101 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
import { computed, watch } from 'vue' |
||||
import { useI18n } from 'vue-i18n' |
||||
import type { IJsonItem } from '../types' |
||||
|
||||
export function useDependentTimeout(model: { |
||||
[field: string]: any |
||||
}): IJsonItem[] { |
||||
const { t } = useI18n() |
||||
const timeCompleteSpan = computed(() => (model.timeoutShowFlag ? 24 : 0)) |
||||
const timeCompleteEnableSpan = computed(() => (model.timeoutFlag ? 12 : 0)) |
||||
|
||||
const strategyOptions = [ |
||||
{ |
||||
label: t('project.node.timeout_alarm'), |
||||
value: 'WARN' |
||||
}, |
||||
{ |
||||
label: t('project.node.timeout_failure'), |
||||
value: 'FAILED' |
||||
} |
||||
] |
||||
watch( |
||||
() => model.timeoutFlag, |
||||
(timeoutFlag) => { |
||||
model.timeoutNotifyStrategy = timeoutFlag ? ['WARN'] : [] |
||||
model.timeout = timeoutFlag ? 30 : null |
||||
} |
||||
) |
||||
|
||||
return [ |
||||
{ |
||||
type: 'switch', |
||||
field: 'timeoutShowFlag', |
||||
name: t('project.node.timeout_alarm') |
||||
}, |
||||
{ |
||||
type: 'switch', |
||||
field: 'timeoutFlag', |
||||
name: t('project.node.waiting_dependent_complete'), |
||||
props: { |
||||
'on-update:value': (value: boolean) => { |
||||
model.timeoutNotifyStrategy = value ? ['WARN'] : null |
||||
model.timeout = value ? 30 : null |
||||
} |
||||
}, |
||||
span: timeCompleteSpan |
||||
}, |
||||
{ |
||||
type: 'input-number', |
||||
field: 'timeout', |
||||
name: t('project.node.timeout_period'), |
||||
span: timeCompleteEnableSpan, |
||||
props: { |
||||
max: Math.pow(9, 10) - 1 |
||||
}, |
||||
slots: { |
||||
suffix: () => t('project.node.minute') |
||||
}, |
||||
validate: { |
||||
trigger: ['input'], |
||||
validator(validate: any, value: number) { |
||||
if (model.timeoutFlag && !/^[1-9]\d*$/.test(String(value))) { |
||||
return new Error(t('project.node.timeout_period_tips')) |
||||
} |
||||
} |
||||
} |
||||
}, |
||||
{ |
||||
type: 'checkbox', |
||||
field: 'timeoutNotifyStrategy', |
||||
name: t('project.node.timeout_strategy'), |
||||
options: strategyOptions, |
||||
span: timeCompleteEnableSpan, |
||||
validate: { |
||||
trigger: ['input'], |
||||
validator(validate: any, value: []) { |
||||
if (model.waitCompleteTimeoutEnable && !value.length) { |
||||
return new Error(t('project.node.timeout_strategy_tips')) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
] |
||||
} |
@ -0,0 +1,318 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
import { ref, onMounted, watch } from 'vue' |
||||
import { useI18n } from 'vue-i18n' |
||||
import { useRelationCustomParams, useDependentTimeout } from '.' |
||||
import { queryProjectCreatedAndAuthorizedByUser } from '@/service/modules/projects' |
||||
import { |
||||
queryAllByProjectCode, |
||||
getTasksByDefinitionCode |
||||
} from '@/service/modules/process-definition' |
||||
import type { IJsonItem, IDependpendItem, IDependTask } from '../types' |
||||
|
||||
export function useDependent(model: { [field: string]: any }): IJsonItem[] { |
||||
const { t } = useI18n() |
||||
const projectList = ref([] as { label: string; value: number }[]) |
||||
const processCache = {} as { |
||||
[key: number]: { label: string; value: number }[] |
||||
} |
||||
const taskCache = {} as { |
||||
[key: number]: { label: string; value: number }[] |
||||
} |
||||
|
||||
const CYCLE_LIST = [ |
||||
{ |
||||
value: 'month', |
||||
label: t('project.node.month') |
||||
}, |
||||
{ |
||||
value: 'week', |
||||
label: t('project.node.week') |
||||
}, |
||||
{ |
||||
value: 'day', |
||||
label: t('project.node.day') |
||||
}, |
||||
{ |
||||
value: 'hour', |
||||
label: t('project.node.hour') |
||||
} |
||||
] |
||||
const DATE_LSIT = { |
||||
hour: [ |
||||
{ |
||||
value: 'currentHour', |
||||
label: t('project.node.current_hour') |
||||
}, |
||||
{ |
||||
value: 'last1Hour', |
||||
label: t('project.node.last_1_hour') |
||||
}, |
||||
{ |
||||
value: 'last2Hours', |
||||
label: t('project.node.last_2_hour') |
||||
}, |
||||
{ |
||||
value: 'last3Hours', |
||||
label: t('project.node.last_3_hour') |
||||
}, |
||||
{ |
||||
value: 'last24Hours', |
||||
label: t('project.node.last_24_hour') |
||||
} |
||||
], |
||||
day: [ |
||||
{ |
||||
value: 'today', |
||||
label: t('project.node.today') |
||||
}, |
||||
{ |
||||
value: 'last1Days', |
||||
label: t('project.node.last_1_days') |
||||
}, |
||||
{ |
||||
value: 'last2Days', |
||||
label: t('project.node.last_2_days') |
||||
}, |
||||
{ |
||||
value: 'last3Days', |
||||
label: t('project.node.last_3_days') |
||||
}, |
||||
{ |
||||
value: 'last7Days', |
||||
label: t('project.node.last_7_days') |
||||
} |
||||
], |
||||
week: [ |
||||
{ |
||||
value: 'thisWeek', |
||||
label: t('project.node.this_week') |
||||
}, |
||||
{ |
||||
value: 'lastWeek', |
||||
label: t('project.node.last_week') |
||||
}, |
||||
{ |
||||
value: 'lastMonday', |
||||
label: t('project.node.last_monday') |
||||
}, |
||||
{ |
||||
value: 'lastTuesday', |
||||
label: t('project.node.last_tuesday') |
||||
}, |
||||
{ |
||||
value: 'lastWednesday', |
||||
label: t('project.node.last_wednesday') |
||||
}, |
||||
{ |
||||
value: 'lastThursday', |
||||
label: t('project.node.last_thursday') |
||||
}, |
||||
{ |
||||
value: 'lastFriday', |
||||
label: t('project.node.last_friday') |
||||
}, |
||||
{ |
||||
value: 'lastSaturday', |
||||
label: t('project.node.last_saturday') |
||||
}, |
||||
{ |
||||
value: 'lastSunday', |
||||
label: t('project.node.last_sunday') |
||||
} |
||||
], |
||||
month: [ |
||||
{ |
||||
value: 'thisMonth', |
||||
label: t('project.node.this_month') |
||||
}, |
||||
{ |
||||
value: 'lastMonth', |
||||
label: t('project.node.last_month') |
||||
}, |
||||
{ |
||||
value: 'lastMonthBegin', |
||||
label: t('project.node.last_month_begin') |
||||
}, |
||||
{ |
||||
value: 'lastMonthEnd', |
||||
label: t('project.node.last_month_end') |
||||
} |
||||
] |
||||
} |
||||
|
||||
const getProjectList = async () => { |
||||
try { |
||||
const result = await queryProjectCreatedAndAuthorizedByUser() |
||||
projectList.value = result.map( |
||||
(item: { code: number; name: string }) => ({ |
||||
value: item.code, |
||||
label: item.name |
||||
}) |
||||
) |
||||
return projectList |
||||
} catch (err) {} |
||||
} |
||||
const getProcessList = async (code: number) => { |
||||
if (processCache[code]) { |
||||
return processCache[code] |
||||
} |
||||
try { |
||||
const result = await queryAllByProjectCode(code) |
||||
const processList = result.map( |
||||
(item: { processDefinition: { code: number; name: string } }) => ({ |
||||
value: item.processDefinition.code, |
||||
label: item.processDefinition.name |
||||
}) |
||||
) |
||||
processCache[code] = processList |
||||
|
||||
return processList |
||||
} catch (err) {} |
||||
} |
||||
|
||||
const getTaskList = async (code: number, processCode: number) => { |
||||
if (taskCache[processCode]) { |
||||
return taskCache[processCode] |
||||
} |
||||
try { |
||||
const result = await getTasksByDefinitionCode(code, processCode) |
||||
const taskList = result.map((item: { code: number; name: string }) => ({ |
||||
value: item.code, |
||||
label: item.name |
||||
})) |
||||
taskList.unshift({ |
||||
value: 0, |
||||
label: 'ALL' |
||||
}) |
||||
taskCache[processCode] = taskList |
||||
return taskList |
||||
} catch (err) {} |
||||
} |
||||
|
||||
onMounted(() => { |
||||
getProjectList() |
||||
}) |
||||
|
||||
watch( |
||||
() => model.dependTaskList, |
||||
(value) => { |
||||
value.forEach((item: IDependTask) => { |
||||
if (!item.dependItemList?.length) return |
||||
|
||||
item.dependItemList?.forEach(async (dependItem: IDependpendItem) => { |
||||
if (dependItem.projectCode) { |
||||
dependItem.definitionCodeOptions = await getProcessList( |
||||
dependItem.projectCode |
||||
) |
||||
} |
||||
if (dependItem.projectCode && dependItem.definitionCode) { |
||||
dependItem.depTaskCodeOptions = await getTaskList( |
||||
dependItem.projectCode, |
||||
dependItem.definitionCode |
||||
) |
||||
} |
||||
console.log(dependItem) |
||||
if (dependItem.cycle) { |
||||
dependItem.dateOptions = DATE_LSIT[dependItem.cycle] |
||||
} |
||||
}) |
||||
}) |
||||
} |
||||
) |
||||
|
||||
return [ |
||||
...useDependentTimeout(model), |
||||
...useRelationCustomParams({ |
||||
model, |
||||
children: (i: number = 0) => ({ |
||||
type: 'custom-parameters', |
||||
field: 'dependItemList', |
||||
span: 18, |
||||
children: [ |
||||
(j = 0) => ({ |
||||
type: 'select', |
||||
field: 'projectCode', |
||||
span: 12, |
||||
props: { |
||||
filterable: true, |
||||
onUpdateValue: async (projectCode: number) => { |
||||
const item = model.dependTaskList[i].dependItemList[j] |
||||
item.definitionCodeOptions = await getProcessList(projectCode) |
||||
item.depTaskCode = null |
||||
item.definitionCode = null |
||||
} |
||||
}, |
||||
options: projectList |
||||
}), |
||||
(j: number = 0) => ({ |
||||
type: 'select', |
||||
field: 'definitionCode', |
||||
span: 12, |
||||
props: { |
||||
filterable: true, |
||||
onUpdateValue: async (processCode: number) => { |
||||
const item = model.dependTaskList[i].dependItemList[j] |
||||
item.depTaskCodeOptions = await getTaskList( |
||||
item.projectCode, |
||||
processCode |
||||
) |
||||
item.depTaskCode = 0 |
||||
} |
||||
}, |
||||
options: |
||||
model.dependTaskList[i]?.dependItemList[j] |
||||
?.definitionCodeOptions || [] |
||||
}), |
||||
(j: number = 0) => ({ |
||||
type: 'select', |
||||
field: 'depTaskCode', |
||||
span: 12, |
||||
props: { |
||||
filterable: true |
||||
}, |
||||
options: |
||||
model.dependTaskList[i]?.dependItemList[j]?.depTaskCodeOptions || |
||||
[] |
||||
}), |
||||
(j: number = 0) => ({ |
||||
type: 'select', |
||||
field: 'cycle', |
||||
span: 12, |
||||
props: { |
||||
onUpdateValue: (value: 'month') => { |
||||
model.dependTaskList[i].dependItemList[j].dateOptions = |
||||
DATE_LSIT[value] |
||||
} |
||||
}, |
||||
options: CYCLE_LIST |
||||
}), |
||||
(j: number = 0) => ({ |
||||
type: 'select', |
||||
field: 'dateValue', |
||||
span: 12, |
||||
options: |
||||
model.dependTaskList[i]?.dependItemList[j]?.dateOptions || [] |
||||
}) |
||||
] |
||||
}), |
||||
childrenField: 'dependItemList', |
||||
name: 'add_dependency' |
||||
}) |
||||
] |
||||
} |
@ -0,0 +1,101 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF licenses this file to You under the Apache License, Version 2.0 |
||||
* (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
import { ref, reactive, watch } from 'vue' |
||||
import * as Fields from '../fields/index' |
||||
import type { IJsonItem, INodeData, ITaskData } from '../types' |
||||
|
||||
export function useDependent({ |
||||
projectCode, |
||||
from = 0, |
||||
readonly, |
||||
data |
||||
}: { |
||||
projectCode: number |
||||
from?: number |
||||
readonly?: boolean |
||||
data?: ITaskData |
||||
}) { |
||||
const taskCodeOptions = ref([] as { label: string; value: number }[]) |
||||
const model = reactive({ |
||||
taskType: 'DEPENDENT', |
||||
name: '', |
||||
flag: 'YES', |
||||
description: '', |
||||
timeoutShowFlag: false, |
||||
localParams: [], |
||||
environmentCode: null, |
||||
failRetryInterval: 1, |
||||
failRetryTimes: 0, |
||||
workerGroup: 'default', |
||||
delayTime: 0, |
||||
relation: 'AND', |
||||
dependTaskList: [], |
||||
preTasks: [], |
||||
timeoutNotifyStrategy: [], |
||||
timeout: 30, |
||||
timeoutFlag: false, |
||||
...data |
||||
} as INodeData) |
||||
|
||||
let extra: IJsonItem[] = [] |
||||
if (from === 1) { |
||||
extra = [ |
||||
Fields.useTaskType(model, readonly), |
||||
Fields.useProcessName({ |
||||
model, |
||||
projectCode, |
||||
isCreate: !data?.id, |
||||
from, |
||||
processName: data?.processName, |
||||
code: data?.code |
||||
}) |
||||
] |
||||
} |
||||
|
||||
watch( |
||||
() => model.preTasks, |
||||
() => { |
||||
taskCodeOptions.value = |
||||
model.preTaskOptions |
||||
?.filter((task: { code: number }) => |
||||
model.preTasks?.includes(task.code) |
||||
) |
||||
.map((task: { code: number; name: string }) => ({ |
||||
value: task.code, |
||||
label: task.name |
||||
})) || [] |
||||
} |
||||
) |
||||
|
||||
return { |
||||
json: [ |
||||
Fields.useName(), |
||||
...extra, |
||||
Fields.useRunFlag(), |
||||
Fields.useDescription(), |
||||
Fields.useTaskPriority(), |
||||
Fields.useWorkerGroup(), |
||||
Fields.useEnvironmentName(model, !data?.id), |
||||
...Fields.useTaskGroup(model, projectCode), |
||||
...Fields.useFailed(), |
||||
...Fields.useDependent(model), |
||||
Fields.usePreTasks(model) |
||||
] as IJsonItem[], |
||||
model |
||||
} |
||||
} |
Loading…
Reference in new issue