Skip to content

Commit dfcb724

Browse files
committed
refactor: Support string,json,num types
1 parent a01f21e commit dfcb724

File tree

2 files changed

+85
-20
lines changed

2 files changed

+85
-20
lines changed

apps/application/flow/step_node/variable_assign_node/impl/base_variable_assign_node.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ def execute(self, variable_list, stream, **kwargs) -> NodeResult:
2323
'input_value': self.get_reference_content(variable['fields']),
2424
}
2525
if variable['source'] == 'custom':
26-
if variable['type'] in ['dict', 'array']:
26+
if variable['type'] == 'json':
2727
if isinstance(variable['value'], dict) or isinstance(variable['value'], list):
2828
val = variable['value']
2929
else:
3030
val = json.loads(variable['value'])
3131
self.workflow_manage.context[variable['fields'][1]] = val
3232
result['output_value'] = variable['value'] = val
3333
else:
34-
self.workflow_manage.context[variable['fields'][1]] = variable['value']
35-
result['output_value'] = variable['value']
34+
# 变量解析 例如:{{global.xxx}}
35+
val = self.workflow_manage.generate_prompt(variable['value'])
36+
self.workflow_manage.context[variable['fields'][1]] = val
37+
result['output_value'] = val
3638
else:
3739
reference = self.get_reference_content(variable['reference'])
3840
self.workflow_manage.context[variable['fields'][1]] = reference

ui/src/workflow/nodes/variable-assign-node/index.vue

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,85 @@
6060
</el-select>
6161
</div>
6262
</template>
63-
<div v-if="item.source === 'custom'" class="flex">
64-
<el-select v-model="item.type" style="width: 130px;">
65-
<el-option v-for="item in typeOptions" :key="item" :label="item" :value="item" />
66-
</el-select>
67-
<el-input
68-
class="ml-4"
69-
v-model="item.value"
70-
:placeholder="$t('common.inputPlaceholder')"
71-
show-word-limit
72-
clearable
73-
@wheel="wheel"
74-
></el-input>
75-
</div>
76-
63+
</el-form-item>
64+
<div v-if="item.source === 'custom'" class="flex">
65+
<el-row :gutter="8">
66+
<el-col :span="8">
67+
<el-select v-model="item.type" style="width: 130px;">
68+
<el-option v-for="item in typeOptions" :key="item" :label="item"
69+
:value="item" />
70+
</el-select>
71+
</el-col>
72+
<el-col :span="16">
73+
<el-form-item v-if="item.type === 'string'"
74+
:prop="'variable_list.' + index + '.value'"
75+
:rules="{
76+
message: t('dynamicsForm.tip.requiredMessage'),
77+
trigger: 'blur',
78+
required: true
79+
}"
80+
>
81+
<el-input
82+
class="ml-4"
83+
v-model="item.value"
84+
:placeholder="$t('common.inputPlaceholder')"
85+
show-word-limit
86+
clearable
87+
@wheel="wheel"
88+
></el-input>
89+
</el-form-item>
90+
<el-form-item v-else-if="item.type ==='num'"
91+
:prop="'variable_list.' + index + '.value'"
92+
:rules="{
93+
message: t('dynamicsForm.tip.requiredMessage'),
94+
trigger: 'blur',
95+
required: true
96+
}"
97+
>
98+
<el-input-number
99+
class="ml-4"
100+
v-model="item.value"
101+
></el-input-number>
102+
</el-form-item>
103+
<el-form-item v-else-if="item.type === 'json'"
104+
:prop="'variable_list.' + index + '.value'"
105+
:rules="[{
106+
message: t('dynamicsForm.tip.requiredMessage'),
107+
trigger: 'blur',
108+
required: true
109+
},
110+
{
111+
validator: (rule:any, value:any, callback:any) => {
112+
try {
113+
JSON.parse(value);
114+
callback(); // Valid JSON
115+
} catch (e) {
116+
callback(new Error('Invalid JSON format'));
117+
}
118+
},
119+
trigger: 'blur',
120+
}]"
121+
>
122+
<el-input
123+
class="ml-4"
124+
v-model="item.value"
125+
:placeholder="$t('common.inputPlaceholder')"
126+
type="textarea"
127+
></el-input>
128+
</el-form-item>
129+
</el-col>
130+
</el-row>
131+
</div>
132+
<el-form-item v-else>
77133
<NodeCascader
78-
v-else
79134
ref="nodeCascaderRef2"
80135
:nodeModel="nodeModel"
81136
class="w-full"
82137
:placeholder="$t('views.applicationWorkflow.variable.placeholder')"
83138
v-model="item.reference"
84139
/>
85140
</el-form-item>
141+
86142
</el-card>
87143
</template>
88144
<el-button link type="primary" @click="addVariable">
@@ -101,10 +157,11 @@ import NodeCascader from '@/workflow/common/NodeCascader.vue'
101157
import { computed, onMounted, ref } from 'vue'
102158
import { isLastNode } from '@/workflow/common/data'
103159
import { randomId } from '@/utils/utils'
160+
import { t } from '@/locales'
104161
105162
const props = defineProps<{ nodeModel: any }>()
106163
107-
const typeOptions = ['string', 'int', 'dict', 'array', 'float']
164+
const typeOptions = ['string', 'num', 'json']
108165
109166
const wheel = (e: any) => {
110167
if (e.ctrlKey === true) {
@@ -149,8 +206,14 @@ function submitDialog(val: string) {
149206
150207
const replyNodeFormRef = ref()
151208
const nodeCascaderRef = ref()
209+
const nodeCascaderRef2 = ref()
152210
const validate = async () => {
153-
return Promise.all([replyNodeFormRef.value?.validate()]).catch((err: any) => {
211+
// console.log(replyNodeFormRef.value.validate())
212+
return Promise.all([
213+
replyNodeFormRef.value?.validate(),
214+
...nodeCascaderRef.value.map((item: any) => item.validate()),
215+
...nodeCascaderRef2.value.map((item: any) => item.validate())
216+
]).catch((err: any) => {
154217
return Promise.reject({ node: props.nodeModel, errMessage: err })
155218
})
156219
}

0 commit comments

Comments
 (0)