refactor: Support string,json,num types

This commit is contained in:
CaptainB 2025-02-25 12:29:26 +08:00 committed by 刘瑞斌
parent a01f21e3ac
commit dfcb724502
2 changed files with 85 additions and 20 deletions

View File

@ -23,7 +23,7 @@ class BaseVariableAssignNode(IVariableAssignNode):
'input_value': self.get_reference_content(variable['fields']),
}
if variable['source'] == 'custom':
if variable['type'] in ['dict', 'array']:
if variable['type'] == 'json':
if isinstance(variable['value'], dict) or isinstance(variable['value'], list):
val = variable['value']
else:
@ -31,8 +31,10 @@ class BaseVariableAssignNode(IVariableAssignNode):
self.workflow_manage.context[variable['fields'][1]] = val
result['output_value'] = variable['value'] = val
else:
self.workflow_manage.context[variable['fields'][1]] = variable['value']
result['output_value'] = variable['value']
# 变量解析 例如:{{global.xxx}}
val = self.workflow_manage.generate_prompt(variable['value'])
self.workflow_manage.context[variable['fields'][1]] = val
result['output_value'] = val
else:
reference = self.get_reference_content(variable['reference'])
self.workflow_manage.context[variable['fields'][1]] = reference

View File

@ -60,22 +60,77 @@
</el-select>
</div>
</template>
<div v-if="item.source === 'custom'" class="flex">
<el-select v-model="item.type" style="width: 130px;">
<el-option v-for="item in typeOptions" :key="item" :label="item" :value="item" />
</el-select>
<el-input
class="ml-4"
v-model="item.value"
:placeholder="$t('common.inputPlaceholder')"
show-word-limit
clearable
@wheel="wheel"
></el-input>
</div>
</el-form-item>
<div v-if="item.source === 'custom'" class="flex">
<el-row :gutter="8">
<el-col :span="8">
<el-select v-model="item.type" style="width: 130px;">
<el-option v-for="item in typeOptions" :key="item" :label="item"
:value="item" />
</el-select>
</el-col>
<el-col :span="16">
<el-form-item v-if="item.type === 'string'"
:prop="'variable_list.' + index + '.value'"
:rules="{
message: t('dynamicsForm.tip.requiredMessage'),
trigger: 'blur',
required: true
}"
>
<el-input
class="ml-4"
v-model="item.value"
:placeholder="$t('common.inputPlaceholder')"
show-word-limit
clearable
@wheel="wheel"
></el-input>
</el-form-item>
<el-form-item v-else-if="item.type ==='num'"
:prop="'variable_list.' + index + '.value'"
:rules="{
message: t('dynamicsForm.tip.requiredMessage'),
trigger: 'blur',
required: true
}"
>
<el-input-number
class="ml-4"
v-model="item.value"
></el-input-number>
</el-form-item>
<el-form-item v-else-if="item.type === 'json'"
:prop="'variable_list.' + index + '.value'"
:rules="[{
message: t('dynamicsForm.tip.requiredMessage'),
trigger: 'blur',
required: true
},
{
validator: (rule:any, value:any, callback:any) => {
try {
JSON.parse(value);
callback(); // Valid JSON
} catch (e) {
callback(new Error('Invalid JSON format'));
}
},
trigger: 'blur',
}]"
>
<el-input
class="ml-4"
v-model="item.value"
:placeholder="$t('common.inputPlaceholder')"
type="textarea"
></el-input>
</el-form-item>
</el-col>
</el-row>
</div>
<el-form-item v-else>
<NodeCascader
v-else
ref="nodeCascaderRef2"
:nodeModel="nodeModel"
class="w-full"
@ -83,6 +138,7 @@
v-model="item.reference"
/>
</el-form-item>
</el-card>
</template>
<el-button link type="primary" @click="addVariable">
@ -101,10 +157,11 @@ import NodeCascader from '@/workflow/common/NodeCascader.vue'
import { computed, onMounted, ref } from 'vue'
import { isLastNode } from '@/workflow/common/data'
import { randomId } from '@/utils/utils'
import { t } from '@/locales'
const props = defineProps<{ nodeModel: any }>()
const typeOptions = ['string', 'int', 'dict', 'array', 'float']
const typeOptions = ['string', 'num', 'json']
const wheel = (e: any) => {
if (e.ctrlKey === true) {
@ -149,8 +206,14 @@ function submitDialog(val: string) {
const replyNodeFormRef = ref()
const nodeCascaderRef = ref()
const nodeCascaderRef2 = ref()
const validate = async () => {
return Promise.all([replyNodeFormRef.value?.validate()]).catch((err: any) => {
// console.log(replyNodeFormRef.value.validate())
return Promise.all([
replyNodeFormRef.value?.validate(),
...nodeCascaderRef.value.map((item: any) => item.validate()),
...nodeCascaderRef2.value.map((item: any) => item.validate())
]).catch((err: any) => {
return Promise.reject({ node: props.nodeModel, errMessage: err })
})
}