Browse Source
* add the form of the switch task * add the component of the switch task * developed the form of the switch task * developed the form of the switch task3.0.0/version-upgrade
calvin
3 years ago
committed by
GitHub
12 changed files with 392 additions and 3 deletions
@ -0,0 +1,153 @@
|
||||
/* |
||||
* 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 { defineComponent, h, unref, renderSlot } from 'vue' |
||||
import { useFormItem } from 'naive-ui/es/_mixins' |
||||
import { |
||||
NFormItemGi, |
||||
NSpace, |
||||
NButton, |
||||
NGrid, |
||||
NGridItem, |
||||
NInput, |
||||
NSelect |
||||
} from 'naive-ui' |
||||
import { PlusOutlined, DeleteOutlined } from '@vicons/antd' |
||||
import type { IJsonItem, FormItemRule } from '../types' |
||||
import getField from '@/components/form/fields/get-field' |
||||
import { formatValidate } from '@/components/form/utils' |
||||
|
||||
const MultiCondition = defineComponent({ |
||||
name: 'MultiCondition', |
||||
emits: ['add'], |
||||
setup(props, ctx) { |
||||
const formItem = useFormItem({}) |
||||
const onAdd = () => void ctx.emit('add') |
||||
|
||||
return { onAdd, disabled: formItem.mergedDisabledRef } |
||||
}, |
||||
render() { |
||||
const { disabled, $slots, onAdd } = this |
||||
|
||||
return h( |
||||
NSpace, |
||||
{ vertical: true, style: { width: '100%' } }, |
||||
{ |
||||
default: () => { |
||||
return [ |
||||
renderSlot($slots, 'default', { disabled }), |
||||
h( |
||||
NButton, |
||||
{ |
||||
circle: true, |
||||
size: 'tiny', |
||||
type: 'info', |
||||
disabled, |
||||
onClick: onAdd |
||||
}, |
||||
{ |
||||
icon: () => h(PlusOutlined) |
||||
} |
||||
) |
||||
] |
||||
} |
||||
} |
||||
) |
||||
} |
||||
}) |
||||
|
||||
export function renderMultiCondition( |
||||
item: IJsonItem, |
||||
fields: { [field: string]: any }, |
||||
rules: { [key: string]: FormItemRule }[] |
||||
) { |
||||
let ruleItem: { [key: string]: FormItemRule } = {} |
||||
|
||||
// the fields is the data of the task definition.
|
||||
// the item is the options of this component in the form.
|
||||
const { field, children = [] } = item |
||||
|
||||
children.forEach((child: IJsonItem) => { |
||||
if (child.validate) { |
||||
ruleItem[child.field] = formatValidate(child.validate) |
||||
} |
||||
}) |
||||
|
||||
const getChild = (item: object, i: number) => |
||||
children.map((child: IJsonItem) => { |
||||
return h( |
||||
NFormItemGi, |
||||
{ |
||||
showLabel: child.name ? true : false, |
||||
label: child.name ? child.name : '', |
||||
path: `${fields[field]}[${i}].${child.field}`, |
||||
span: unref(child.span) |
||||
}, |
||||
() => getField(child, fields[field][i]) |
||||
) |
||||
}) |
||||
|
||||
//initialize the component by using data
|
||||
const getChildren = ({ disabled }: { disabled: boolean }) => |
||||
fields[field].map((item: object, i: number) => { |
||||
return h(NGrid, { xGap: 10 }, () => [ |
||||
...getChild(item, i), |
||||
h( |
||||
NGridItem, |
||||
{ |
||||
span: 2, |
||||
style: { alignSelf: 'center' } |
||||
}, |
||||
() => |
||||
h( |
||||
NButton, |
||||
{ |
||||
circle: true, |
||||
type: 'error', |
||||
size: 'tiny', |
||||
disabled, |
||||
onClick: () => { |
||||
fields[field].splice(i, 1) |
||||
} |
||||
}, |
||||
{ |
||||
icon: () => h(DeleteOutlined) |
||||
} |
||||
) |
||||
) |
||||
]) |
||||
}) |
||||
|
||||
return h( |
||||
MultiCondition, |
||||
{ |
||||
name: field, |
||||
onAdd: () => { |
||||
const newCondition = {} as any |
||||
children.map((child: IJsonItem) => { |
||||
if (child.field) { |
||||
newCondition[child.field] = null |
||||
} |
||||
}) |
||||
fields[field].push(newCondition) |
||||
} |
||||
}, |
||||
{ |
||||
default: getChildren |
||||
} |
||||
) |
||||
} |
@ -0,0 +1,107 @@
|
||||
/* |
||||
* 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 { nextTick, onMounted, ref, watch } from 'vue' |
||||
import { useI18n } from 'vue-i18n' |
||||
import type { IJsonItem } from '../types' |
||||
import { queryProcessDefinitionByCode } from '@/service/modules/process-definition' |
||||
|
||||
export function useSwitch( |
||||
model: { [field: string]: any }, |
||||
projectCode: number |
||||
): IJsonItem[] { |
||||
const { t } = useI18n() |
||||
const branchFlowOptions = ref([] as any) |
||||
|
||||
const loading = ref(false) |
||||
|
||||
const getOtherTaskDefinitionList = async () => { |
||||
if (loading.value) return |
||||
loading.value = true |
||||
branchFlowOptions.value = [] |
||||
try { |
||||
const res = await queryProcessDefinitionByCode( |
||||
model.processName, |
||||
projectCode |
||||
) |
||||
res?.taskDefinitionList.forEach((item: any) => { |
||||
if (item.code != model.code) { |
||||
branchFlowOptions.value.push({ label: item.name, value: item.code }) |
||||
} |
||||
}) |
||||
loading.value = false |
||||
} catch (err) { |
||||
loading.value = false |
||||
} |
||||
} |
||||
|
||||
watch( |
||||
() => [model.processName, model.nextCode], |
||||
() => { |
||||
if (model.processName) { |
||||
getOtherTaskDefinitionList() |
||||
} |
||||
} |
||||
) |
||||
|
||||
return [ |
||||
{ |
||||
type: 'multi-condition', |
||||
field: 'dependTaskList', |
||||
name: t('project.node.switch_condition'), |
||||
validate: { |
||||
required: true |
||||
}, |
||||
children: [ |
||||
{ |
||||
type: 'input', |
||||
field: 'condition', |
||||
span: 24, |
||||
props: { |
||||
loading: loading, |
||||
type: 'textarea', |
||||
autosize: { minRows: 2 } |
||||
}, |
||||
validate: { |
||||
trigger: ['input', 'blur'], |
||||
required: true |
||||
} |
||||
}, |
||||
{ |
||||
type: 'select', |
||||
field: 'nextNode', |
||||
span: 18, |
||||
name: t('project.node.switch_branch_flow'), |
||||
options: branchFlowOptions, |
||||
validate: { |
||||
trigger: ['input', 'blur'], |
||||
required: true |
||||
} |
||||
} |
||||
] |
||||
}, |
||||
{ |
||||
type: 'select', |
||||
field: 'nextNode', |
||||
span: 24, |
||||
name: t('project.node.switch_branch_flow'), |
||||
props: { |
||||
loading: loading |
||||
}, |
||||
options: branchFlowOptions |
||||
} |
||||
] |
||||
} |
@ -0,0 +1,85 @@
|
||||
/* |
||||
* 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 { reactive } from 'vue' |
||||
import * as Fields from '../fields/index' |
||||
import type { IJsonItem, INodeData, ITaskData } from '../types' |
||||
|
||||
export function useSwitch({ |
||||
projectCode, |
||||
from = 0, |
||||
readonly, |
||||
data |
||||
}: { |
||||
projectCode: number |
||||
from?: number |
||||
readonly?: boolean |
||||
data?: ITaskData |
||||
}) { |
||||
const model = reactive({ |
||||
taskType: 'SWITCH', |
||||
name: '', |
||||
flag: 'YES', |
||||
description: '', |
||||
timeoutFlag: false, |
||||
localParams: [], |
||||
environmentCode: null, |
||||
failRetryInterval: 1, |
||||
failRetryTimes: 0, |
||||
workerGroup: 'default', |
||||
delayTime: 0, |
||||
timeout: 30, |
||||
rawScript: '', |
||||
switchResult: {}, |
||||
dependTaskList: [], |
||||
nextNode: undefined |
||||
} 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 |
||||
}) |
||||
] |
||||
} |
||||
|
||||
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.useDelayTime(model), |
||||
...Fields.useTimeoutAlarm(model), |
||||
...Fields.useSwitch(model, projectCode), |
||||
Fields.usePreTasks(model) |
||||
] as IJsonItem[], |
||||
model |
||||
} |
||||
} |
Loading…
Reference in new issue