refactor: Support string,json,num types
This commit is contained in:
parent
a01f21e3ac
commit
dfcb724502
@ -23,7 +23,7 @@ class BaseVariableAssignNode(IVariableAssignNode):
|
|||||||
'input_value': self.get_reference_content(variable['fields']),
|
'input_value': self.get_reference_content(variable['fields']),
|
||||||
}
|
}
|
||||||
if variable['source'] == 'custom':
|
if variable['source'] == 'custom':
|
||||||
if variable['type'] in ['dict', 'array']:
|
if variable['type'] == 'json':
|
||||||
if isinstance(variable['value'], dict) or isinstance(variable['value'], list):
|
if isinstance(variable['value'], dict) or isinstance(variable['value'], list):
|
||||||
val = variable['value']
|
val = variable['value']
|
||||||
else:
|
else:
|
||||||
@ -31,8 +31,10 @@ class BaseVariableAssignNode(IVariableAssignNode):
|
|||||||
self.workflow_manage.context[variable['fields'][1]] = val
|
self.workflow_manage.context[variable['fields'][1]] = val
|
||||||
result['output_value'] = variable['value'] = val
|
result['output_value'] = variable['value'] = val
|
||||||
else:
|
else:
|
||||||
self.workflow_manage.context[variable['fields'][1]] = variable['value']
|
# 变量解析 例如:{{global.xxx}}
|
||||||
result['output_value'] = variable['value']
|
val = self.workflow_manage.generate_prompt(variable['value'])
|
||||||
|
self.workflow_manage.context[variable['fields'][1]] = val
|
||||||
|
result['output_value'] = val
|
||||||
else:
|
else:
|
||||||
reference = self.get_reference_content(variable['reference'])
|
reference = self.get_reference_content(variable['reference'])
|
||||||
self.workflow_manage.context[variable['fields'][1]] = reference
|
self.workflow_manage.context[variable['fields'][1]] = reference
|
||||||
|
|||||||
@ -60,22 +60,77 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<div v-if="item.source === 'custom'" class="flex">
|
</el-form-item>
|
||||||
<el-select v-model="item.type" style="width: 130px;">
|
<div v-if="item.source === 'custom'" class="flex">
|
||||||
<el-option v-for="item in typeOptions" :key="item" :label="item" :value="item" />
|
<el-row :gutter="8">
|
||||||
</el-select>
|
<el-col :span="8">
|
||||||
<el-input
|
<el-select v-model="item.type" style="width: 130px;">
|
||||||
class="ml-4"
|
<el-option v-for="item in typeOptions" :key="item" :label="item"
|
||||||
v-model="item.value"
|
:value="item" />
|
||||||
:placeholder="$t('common.inputPlaceholder')"
|
</el-select>
|
||||||
show-word-limit
|
</el-col>
|
||||||
clearable
|
<el-col :span="16">
|
||||||
@wheel="wheel"
|
<el-form-item v-if="item.type === 'string'"
|
||||||
></el-input>
|
:prop="'variable_list.' + index + '.value'"
|
||||||
</div>
|
: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
|
<NodeCascader
|
||||||
v-else
|
|
||||||
ref="nodeCascaderRef2"
|
ref="nodeCascaderRef2"
|
||||||
:nodeModel="nodeModel"
|
:nodeModel="nodeModel"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
@ -83,6 +138,7 @@
|
|||||||
v-model="item.reference"
|
v-model="item.reference"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
</el-card>
|
</el-card>
|
||||||
</template>
|
</template>
|
||||||
<el-button link type="primary" @click="addVariable">
|
<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 { computed, onMounted, ref } from 'vue'
|
||||||
import { isLastNode } from '@/workflow/common/data'
|
import { isLastNode } from '@/workflow/common/data'
|
||||||
import { randomId } from '@/utils/utils'
|
import { randomId } from '@/utils/utils'
|
||||||
|
import { t } from '@/locales'
|
||||||
|
|
||||||
const props = defineProps<{ nodeModel: any }>()
|
const props = defineProps<{ nodeModel: any }>()
|
||||||
|
|
||||||
const typeOptions = ['string', 'int', 'dict', 'array', 'float']
|
const typeOptions = ['string', 'num', 'json']
|
||||||
|
|
||||||
const wheel = (e: any) => {
|
const wheel = (e: any) => {
|
||||||
if (e.ctrlKey === true) {
|
if (e.ctrlKey === true) {
|
||||||
@ -149,8 +206,14 @@ function submitDialog(val: string) {
|
|||||||
|
|
||||||
const replyNodeFormRef = ref()
|
const replyNodeFormRef = ref()
|
||||||
const nodeCascaderRef = ref()
|
const nodeCascaderRef = ref()
|
||||||
|
const nodeCascaderRef2 = ref()
|
||||||
const validate = async () => {
|
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 })
|
return Promise.reject({ node: props.nodeModel, errMessage: err })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user