-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
407 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
ui/src/workflow/nodes/base-node/component/ApiFieldFormDialog.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
121
ui/src/workflow/nodes/base-node/component/ApiInputFieldTable.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.