Skip to content

Commit cb361fa

Browse files
committed
fix: enhance localization handling and improve field refresh logic in data and index components
1 parent 87de043 commit cb361fa

3 files changed

Lines changed: 41 additions & 30 deletions

File tree

ui/src/workflow/common/NodeCascader.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
</template>
2424

2525
<script setup lang="ts">
26-
import { ref, onMounted, computed, inject } from 'vue'
26+
import { computed, inject, onMounted, ref } from 'vue'
2727
import { iconComponent } from '../icons/utils'
2828
import { t } from '@/locales'
2929
import { WorkflowMode } from '@/enums/application'
30+
3031
const props = defineProps<{
3132
nodeModel: any
3233
modelValue: Array<any>
@@ -108,7 +109,7 @@ const getOptionsValue = () => {
108109
)
109110
: get_up_node_field_list(false, true).filter((v: any) => v.children && v.children.length > 0)
110111
} else {
111-
const result = props.global
112+
return props.global
112113
? props.nodeModel
113114
.get_up_node_field_list(false, true)
114115
.filter(
@@ -118,7 +119,6 @@ const getOptionsValue = () => {
118119
: props.nodeModel
119120
.get_up_node_field_list(false, true)
120121
.filter((v: any) => v.children && v.children.length > 0)
121-
return result
122122
}
123123
}
124124
const initOptions = () => {

ui/src/workflow/common/data.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { WorkflowKind } from './../../enums/application'
22
import { WorkflowType, WorkflowMode } from '@/enums/application'
3-
import { t } from '@/locales'
3+
import i18n, { t } from '@/locales'
4+
import { watch } from 'vue'
45
import call$ from 'dingtalk-jsapi/api/biz/telephone/call'
56

67
export const startNode = {
@@ -1190,9 +1191,9 @@ function defineLocaleGetter(target: any, prop: string, key: string, fallback?: s
11901191
Object.defineProperty(target, prop, {
11911192
configurable: true,
11921193
enumerable: true,
1193-
get: () => overrideValue ?? t(key, fallback as any),
1194+
get: () => overrideValue || t(key, fallback as any),
11941195
set: (value) => {
1195-
overrideValue = value
1196+
overrideValue = value || undefined
11961197
},
11971198
})
11981199
}
@@ -1207,7 +1208,15 @@ function bindLocale(target: any, path: string, key: string, fallback?: string) {
12071208
}
12081209

12091210
function bindFieldLabels(fields: Array<any> | undefined, keys: string[]) {
1210-
fields?.forEach((field, index) => defineLocaleGetter(field, 'label', keys[index]))
1211+
const refresh = () => {
1212+
fields?.forEach((field, index) => {
1213+
if (keys[index]) {
1214+
field.label = t(keys[index])
1215+
}
1216+
})
1217+
}
1218+
refresh()
1219+
watch(i18n.global.locale, refresh)
12111220
}
12121221

12131222
function bindNodeLocale(node: any, textKey: string, labelKey: string, stepNameKey = labelKey) {

ui/src/workflow/nodes/start-node/index.vue

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,29 @@
4848
import { cloneDeep, set } from 'lodash'
4949
import NodeContainer from '@/workflow/common/NodeContainer.vue'
5050
import { copyClick } from '@/utils/clipboard'
51-
import { ref, onMounted } from 'vue'
51+
import { ref, onMounted, watch } from 'vue'
5252
import { t } from '@/locales'
53+
import { useI18n } from 'vue-i18n'
5354
const props = defineProps<{ nodeModel: any }>()
55+
const { locale } = useI18n({ useScope: 'global' })
5456
5557
const showicon = ref(false)
56-
const globalFields = [
58+
const getGlobalFields = () => [
5759
{ label: t('workflow.nodes.startNode.currentTime'), value: 'time' },
58-
{
59-
label: t('views.application.form.historyRecord.label'),
60-
value: 'history_context',
61-
},
60+
{ label: t('views.application.form.historyRecord.label'), value: 'history_context' },
6261
{ label: t('aiChat.chatId'), value: 'chat_id' },
63-
{
64-
label: t('aiChat.chatUserId'),
65-
value: 'chat_user_id',
66-
},
67-
{
68-
label: t('aiChat.chatUserType'),
69-
value: 'chat_user_type',
70-
},
71-
{
72-
label: t('aiChat.chatUserGroup'),
73-
value: 'chat_user_group',
74-
},
75-
{
76-
label: t('views.chatUser.title'),
77-
value: 'chat_user',
78-
},
62+
{ label: t('aiChat.chatUserId'), value: 'chat_user_id' },
63+
{ label: t('aiChat.chatUserType'), value: 'chat_user_type' },
64+
{ label: t('aiChat.chatUserGroup'), value: 'chat_user_group' },
65+
{ label: t('views.chatUser.title'), value: 'chat_user' },
7966
]
8067
68+
const refreshStartQuestionField = () => {
69+
const questionFields = [{ label: t('workflow.nodes.startNode.question'), value: 'question' }]
70+
set(props.nodeModel.properties.config, 'fields', questionFields)
71+
set(props.nodeModel.properties, 'fields', questionFields)
72+
}
73+
8174
const getRefreshFieldList = () => {
8275
const user_input_fields = props.nodeModel.graphModel.nodes
8376
.filter((v: any) => v.id === 'base-node')
@@ -98,7 +91,7 @@ const getRefreshFieldList = () => {
9891
}
9992
const refreshFieldList = () => {
10093
const refreshFieldList = getRefreshFieldList()
101-
set(props.nodeModel.properties.config, 'globalFields', [...globalFields, ...refreshFieldList])
94+
set(props.nodeModel.properties.config, 'globalFields', [...getGlobalFields(), ...refreshFieldList])
10295
}
10396
10497
const refreshChatFieldList = () => {
@@ -179,6 +172,15 @@ const refreshLongTermConfig = () => {
179172
props.nodeModel.graphModel.eventCenter.on('refreshLongTermConfig', refreshLongTermConfig)
180173
181174
onMounted(() => {
175+
refreshStartQuestionField()
176+
refreshChatFieldList()
177+
refreshFieldList()
178+
refreshFileUploadConfig()
179+
refreshLongTermConfig()
180+
})
181+
182+
watch(locale, () => {
183+
refreshStartQuestionField()
182184
refreshChatFieldList()
183185
refreshFieldList()
184186
refreshFileUploadConfig()

0 commit comments

Comments
 (0)