Skip to content

Commit

Permalink
refactor: 高级应用区分用户输入和接口传入的参数
Browse files Browse the repository at this point in the history
  • Loading branch information
liuruibin committed Oct 18, 2024
1 parent ad6d617 commit 8da8c3e
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 112 deletions.
2 changes: 1 addition & 1 deletion apps/application/serializers/application_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def get_query_api_input(self, application, params):
if work_flow is not None:
for node in work_flow.get('nodes', []):
if node['id'] == 'base-node':
input_field_list = node.get('properties', {}).get('input_field_list', [])
input_field_list = node.get('properties', {}).get('api_input_field_list', node.get('properties', {}).get('input_field_list', []))
if input_field_list is not None:
for field in input_field_list:
if field['assignment_method'] == 'api_input' and field['variable'] in params:
Expand Down
126 changes: 126 additions & 0 deletions ui/src/workflow/nodes/base-node/component/ApiFieldFormDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<template>
<el-dialog
:title="isEdit ? '编辑参数' : '添加参数'"
v-model="dialogVisible"
:close-on-click-modal="false"
:close-on-press-escape="false"
:destroy-on-close="true"
append-to-body
>
<el-form
label-position="top"
ref="fieldFormRef"
:rules="rules"
:model="form"
require-asterisk-position="right"
>
<el-form-item label="参数" prop="variable">
<el-input
v-model="form.variable"
placeholder="请输入参数"
maxlength="64"
show-word-limit
@blur="form.variable = form.variable.trim()"
/>
</el-form-item>

<el-form-item label="是否必填" @click.prevent>
<el-switch size="small" v-model="form.is_required"></el-switch>
</el-form-item>
<el-form-item
label="默认值"
prop="default_value"
:rules="{
required: form.is_required,
message: '请输入默认值',
trigger: 'blur'
}"
>
<el-input
v-model="form.default_value"
placeholder="请输入默认值"
@blur="form.name = form.name.trim()"
/>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
<el-button type="primary" @click="submit(fieldFormRef)" :loading="loading">
{{ isEdit ? '保存' : '添加' }}
</el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { reactive, ref, watch } from 'vue'
import type { FormInstance } from 'element-plus'
import { cloneDeep } from 'lodash'
const emit = defineEmits(['refresh'])
const fieldFormRef = ref()
const loading = ref<boolean>(false)
const isEdit = ref(false)
const form = ref<any>({
name: '',
variable: '',
type: 'input',
is_required: true,
assignment_method: 'api_input',
optionList: [''],
default_value: ''
})
const rules = reactive({
name: [{ required: true, message: '请输入显示名称', trigger: 'blur' }],
variable: [
{ required: true, message: '请输入参数', trigger: 'blur' },
{ pattern: /^[a-zA-Z0-9_]+$/, message: '只能输入字母数字和下划线', trigger: 'blur' }
]
})
const dialogVisible = ref<boolean>(false)
watch(dialogVisible, (bool) => {
if (!bool) {
form.value = {
name: '',
variable: '',
type: 'input',
is_required: true,
assignment_method: 'api_input',
optionList: [''],
default_value: ''
}
isEdit.value = false
}
})
const open = (row: any) => {
if (row) {
form.value = cloneDeep(row)
isEdit.value = true
}
dialogVisible.value = true
}
const close = () => {
dialogVisible.value = false
}
const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return
await formEl.validate((valid) => {
if (valid) {
emit('refresh', form.value)
}
})
}
defineExpose({ open, close })
</script>
<style lang="scss" scoped></style>
121 changes: 121 additions & 0 deletions ui/src/workflow/nodes/base-node/component/ApiInputFieldTable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<template>
<div class="flex-between mb-16">
<h5 class="lighter">{{ '接口传参' }}</h5>
<el-button link type="primary" @click="openAddDialog()">
<el-icon class="mr-4">
<Plus />
</el-icon>
添加
</el-button>
</div>
<el-table
:data="props.nodeModel.properties.api_input_field_list"
class="mb-16"
>
<el-table-column prop="variable" label="参数" />
<el-table-column prop="default_value" label="默认值" />
<el-table-column label="必填">
<template #default="{ row }">
<div @click.stop>
<el-switch disabled size="small" v-model="row.is_required" />
</div>
</template>
</el-table-column>
<el-table-column label="操作" align="left" width="80">
<template #default="{ row, $index }">
<span class="mr-4">
<el-tooltip effect="dark" content="修改" placement="top">
<el-button type="primary" text @click.stop="openAddDialog(row, $index)">
<el-icon><EditPen /></el-icon>
</el-button>
</el-tooltip>
</span>
<el-tooltip effect="dark" content="删除" placement="top">
<el-button type="primary" text @click="deleteField($index)">
<el-icon>
<Delete />
</el-icon>
</el-button>
</el-tooltip>
</template>
</el-table-column>
</el-table>

<ApiFieldFormDialog ref="ApiFieldFormDialogRef" @refresh="refreshFieldList" />

</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { set } from 'lodash'
import ApiFieldFormDialog from './ApiFieldFormDialog.vue'
import { MsgError } from '@/utils/message'
const props = defineProps<{ nodeModel: any }>()
const currentIndex = ref(null)
const ApiFieldFormDialogRef = ref()
const inputFieldList = ref<any[]>([])
function openAddDialog(data?: any, index?: any) {
if (typeof index !== 'undefined') {
currentIndex.value = index
}
ApiFieldFormDialogRef.value.open(data)
}
function deleteField(index: any) {
inputFieldList.value.splice(index, 1)
props.nodeModel.graphModel.eventCenter.emit('refreshFieldList')
}
function refreshFieldList(data: any) {
for (let i = 0; i < inputFieldList.value.length; i++) {
if (inputFieldList.value[i].variable === data.variable && currentIndex.value !== i) {
MsgError('参数已存在: ' + data.variable)
return
}
}
// 查看另一个list又没有重复的
let arr = props.nodeModel.properties.user_input_field_list
for (let i = 0; i < arr.length; i++) {
if (arr[i].variable === data.variable) {
MsgError('参数已存在: ' + data.variable)
return
}
}
if (currentIndex.value !== null) {
inputFieldList.value.splice(currentIndex.value, 1, data)
} else {
inputFieldList.value.push(data)
}
currentIndex.value = null
ApiFieldFormDialogRef.value.close()
props.nodeModel.graphModel.eventCenter.emit('refreshFieldList')
}
onMounted(() => {
if (!props.nodeModel.properties.api_input_field_list) {
if (props.nodeModel.properties.input_field_list) {
props.nodeModel.properties.input_field_list
.filter((item: any) => {
return item.assignment_method === 'api_input'
})
.forEach((item: any) => {
inputFieldList.value.push(item)
})
}
} else {
inputFieldList.value.push(...props.nodeModel.properties.api_input_field_list)
}
set(props.nodeModel.properties, 'api_input_field_list', inputFieldList)
})
</script>


<style scoped lang="scss">
</style>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<el-dialog
:title="isEdit ? '编辑变量' : '添加变量'"
:title="isEdit ? '编辑参数' : '添加参数'"
v-model="dialogVisible"
:close-on-click-modal="false"
:close-on-press-escape="false"
Expand All @@ -14,10 +14,10 @@
:model="form"
require-asterisk-position="right"
>
<el-form-item label="变量" prop="variable">
<el-form-item label="参数" prop="variable">
<el-input
v-model="form.variable"
placeholder="请输入变量"
placeholder="请输入参数"
maxlength="64"
show-word-limit
@blur="form.variable = form.variable.trim()"
Expand Down Expand Up @@ -100,12 +100,6 @@
/>
</el-select>
</el-form-item>
<el-form-item label="赋值方式">
<el-radio-group v-model="form.assignment_method">
<el-radio value="user_input">用户输入</el-radio>
<el-radio value="api_input">接口传参</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
Expand Down Expand Up @@ -142,7 +136,7 @@ const form = ref<any>({
const rules = reactive({
name: [{ required: true, message: '请输入显示名称', trigger: 'blur' }],
variable: [
{ required: true, message: '请输入变量', trigger: 'blur' },
{ required: true, message: '请输入参数', trigger: 'blur' },
{ pattern: /^[a-zA-Z0-9_]+$/, message: '只能输入字母数字和下划线', trigger: 'blur' }
]
})
Expand Down
Loading

0 comments on commit 8da8c3e

Please sign in to comment.