Skip to content

Commit 3bc59b5

Browse files
committed
refactor: 嵌入第三方增加url参数
1 parent 959b2fc commit 3bc59b5

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

ui/src/views/application-overview/component/EmbedDialog.vue

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ import useStore from '@/stores'
5858
5959
const { application } = useStore()
6060
61+
const props = defineProps({
62+
data: Object
63+
})
64+
6165
const emit = defineEmits(['addData'])
6266
6367
const dialogVisible = ref<boolean>(false)
@@ -66,6 +70,8 @@ const source1 = ref('')
6670
6771
const source2 = ref('')
6872
73+
const apiInputParams = ref({})
74+
6975
watch(dialogVisible, (bool) => {
7076
if (!bool) {
7177
source1.value = ''
@@ -75,7 +81,7 @@ watch(dialogVisible, (bool) => {
7581
7682
const open = (val: string) => {
7783
source1.value = `<iframe
78-
src="${application.location + val}"
84+
src="${application.location + val}?${mapToUrlParams(apiInputParams.value)}"
7985
style="width: 100%; height: 100%;"
8086
frameborder="0"
8187
allow="microphone">
@@ -88,12 +94,43 @@ defer
8894
src="${window.location.origin}/api/application/embed?protocol=${window.location.protocol.replace(
8995
':',
9096
''
91-
)}&host=${window.location.host}&token=${val}">
97+
)}&host=${window.location.host}&token=${val}&${mapToUrlParams(apiInputParams.value)}">
9298
<\/script>
9399
`
94100
dialogVisible.value = true
95101
}
96102
103+
function mapToUrlParams(map) {
104+
const params = new URLSearchParams();
105+
106+
map.forEach((item: any) => {
107+
params.append(encodeURIComponent(item.name), encodeURIComponent(item.value));
108+
});
109+
110+
return params.toString(); // 返回 URL 查询字符串
111+
}
112+
113+
watch(() => props.data,
114+
(val) => {
115+
if (val) {
116+
val.work_flow?.nodes
117+
?.filter((v: any) => v.id === 'base-node')
118+
.map((v: any) => {
119+
apiInputParams.value = v.properties.input_field_list
120+
? v.properties.input_field_list
121+
.filter((v: any) => v.assignment_method === 'api_input')
122+
.map((v: any) => {
123+
return {
124+
name: v.variable,
125+
value: v.default_value
126+
}
127+
})
128+
: []
129+
})
130+
}
131+
}
132+
)
133+
97134
defineExpose({ open })
98135
</script>
99136
<style lang="scss" scope>

ui/src/views/application-overview/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
</div>
154154
</div>
155155
</el-scrollbar>
156-
<EmbedDialog ref="EmbedDialogRef" />
156+
<EmbedDialog ref="EmbedDialogRef" :data="detail" />
157157
<APIKeyDialog ref="APIKeyDialogRef" />
158158
<LimitDialog ref="LimitDialogRef" @refresh="refresh" />
159159
<EditAvatarDialog ref="EditAvatarDialogRef" @refresh="refreshIcon" />

0 commit comments

Comments
 (0)