Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions ui/src/views/application/application-card/ApplicationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
import type { ApplicationDetail } from '@/api/types'
import { isWorkFlow } from '@/utils/common'
import { dateFormat } from '@/utils/time'
import applicationAPI from "@/api/admin/workspace/application/application"
import { useRoute, useRouter } from 'vue-router';
import { computed } from 'vue';
import applicationAPI from '@/api/admin/workspace/application/application'

import { computed } from 'vue'
defineOptions({ name: 'ApplicationCard' })
const router = useRouter()

const props = defineProps<{ application: ApplicationDetail; selectable?: boolean; selected?: boolean }>()
import { CHAT_API_BASE_PATH } from '@/api/constants'
const emit = defineEmits<{ click: []; selected: [selected: boolean] }>()

defineSlots<{ 'action-dropdown'?: () => unknown }>()
const apiQuery = computed(() => {
const query = props.application?.work_flow?.nodes?.find(n => n.id === 'base-node')?.properties?.api_input_field_list.map((f: any) => {
return `${f.variable}=${f.default_value}`
}).join('&')
const query = props.application?.work_flow?.nodes
?.find((n) => n.id === 'base-node')
?.properties?.api_input_field_list.map((f: any) => {
return `${f.variable}=${f.default_value}`
})
.join('&')
if (query) {
return '?' + query
}
Expand All @@ -28,18 +31,25 @@ const chatBasePath = CHAT_API_BASE_PATH.replace(/\/api$/, '')
function handleOpen() {
if (!props.selectable) emit('click')
}
const toChat = () => {
applicationAPI.getAccessToken(props.application.id).then(ok => {
function toChat() {
applicationAPI.getAccessToken(props.application.id).then((ok) => {
const accessUrl = ok.access_token ? `${window.location.origin}${chatBasePath}/${ok.access_token}/${apiQuery.value}` : ''
window.open(accessUrl, '_blank')
})
}
</script>

<template>
<MkResourceCard :create_time="application.create_time" :nick_name="application.nick_name || '-'"
:selectable="selectable" :selected="selected" :title="application.name" :class="{ 'cursor-pointer': !selectable }"
@click="handleOpen" @selected="emit('selected', $event)">
<MkResourceCard
:create_time="application.create_time"
:nick_name="application.nick_name || '-'"
:selectable="selectable"
:selected="selected"
:title="application.name"
:class="{ 'cursor-pointer': !selectable }"
@click="handleOpen"
@selected="emit('selected', $event)"
>
<template #icon>
<ApplicationIcon :icon="application.icon" />
</template>
Expand All @@ -55,8 +65,14 @@ const toChat = () => {

<template #footer="{ Action, ActionDropdown }">
<MkStatusLabel v-if="application.is_portal" type="custom" label="已上架" icon="icon_launch" class="text-N600!" />
<MkStatusLabel v-else :active="application.is_publish" active-text="已发布" inactive-text="未发布"
:icon="application.is_publish ? undefined : 'icon_time_filled'" class="text-N600!" />
<MkStatusLabel
v-else
:active="application.is_publish"
active-text="已发布"
inactive-text="未发布"
:icon="application.is_publish ? undefined : 'icon_time_filled'"
class="text-N600!"
/>
<template v-if="application.is_publish">
<el-divider direction="vertical" />
<span class="flex-align-center gap-2">
Expand Down
23 changes: 21 additions & 2 deletions ui/src/views/system/resource-management/application/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SystemWorkspaceApi from '@/api/admin/system/workspace'
import SystemResourceTriggerApi from '@/api/admin/system/resource-management/resource-trigger'
import type { ApplicationDetail, Dict, OptionItem } from '@/api/types'
import { APPLICATION_TYPE } from '@/api/enums'
import { CHAT_API_BASE_PATH } from '@/api/constants'
import { useStore } from '@/stores'
import { datetimeFormat } from '@/utils/time'
import { isWorkFlow, toOrderBy } from '@/utils/common'
Expand All @@ -24,6 +25,24 @@ import perm from '@/permission'

const { auth } = useStore()
const router = useRouter()
const chatBasePath = CHAT_API_BASE_PATH.replace(/\/api$/, '')

function apiQuery(application: ApplicationDetail) {
const query = application?.work_flow?.nodes?.find(n => n.id === 'base-node')?.properties?.api_input_field_list.map((f: any) => {
return `${f.variable}=${f.default_value}`
}).join('&')
if (query) {
return '?' + query
}
return ''
}

function toChat(application: ApplicationDetail) {
return SystemResourceApplicationApi.getAccessToken(application.id).then((ok) => {
const accessUrl = ok.access_token ? `${window.location.origin}${chatBasePath}/${ok.access_token}/${apiQuery(application)}` : ''
window.open(accessUrl, '_blank')
})
}

function handleOpenApplication(application: ApplicationDetail) {
void router.push({ name: 'system-resource-application-detail', params: { applicationId: application.id, type: application.type } })
Expand Down Expand Up @@ -176,9 +195,9 @@ onMounted(() => {
<el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }">
<div class="flex-align-center">
<!-- TODO:对话 -->
<!-- 去对话 -->
<MkTooltip content="去对话">
<el-button text type="primary">
<el-button text type="primary" @click="toChat(row)">
<MkIcon name="icon_new-chat_outlined" />
</el-button>
</MkTooltip>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the issues and suggestions:

1. Potential runtime crash in apiQuery

application?.work_flow?.nodes?.find(...)?.properties?.api_input_field_list.map(...)

The optional chaining stops at .find(...), but then .properties is accessed without ?., and .api_input_field_list.map(...) also lacks ?.. If the node isn't found, or properties / api_input_field_list are undefined, this throws. Fix:

const query = application?.work_flow?.nodes
  ?.find(n => n.id === 'base-node')
  ?.properties?.api_input_field_list
  ?.map((f: any) => `${f.variable}=${f.default_value}`)
  .join('&')

2. Values not URL-encoded
default_value (and variable) may contain spaces, &, =, #, etc., corrupting the query string. Use encodeURIComponent:

`${encodeURIComponent(f.variable)}=${encodeURIComponent(f.default_value ?? '')}`

3. Double slash in the URL when no query params

`${origin}${chatBasePath}/${token}/${apiQuery(application)}`

apiQuery returns '' when empty, so you get .../{token}/ with a trailing slash (or /{token}/?a=b). Compare the concatenation carefully — you likely want .../${token} and append apiQuery directly (since it already includes the leading ?), or strip the trailing /.

4. window.open with an empty URL
When access_token is falsy, accessUrl is '' and window.open('', '_blank') opens a blank tab. Guard against it or show an error message:

if (!ok.access_token) { /* show toast */ return }

5. Unused parameter / typing
ApplicationDetail is imported as a type, good. But f: any weakens typing — define an interface for the api field list if available.

6. Naming
apiQuery returns a query string (with leading ?); consider renaming to buildApiQuery / getApiQueryString for clarity.

7. Error handling in toChat
The .then chain has no .catch; a failed token request produces an unhandled rejection. Add .catch (or use async/await with try/catch).

8. Re-entrancy on button click
No loading state preventing multiple rapid clicks → multiple tabs. Consider disabling/spinner while the request is in-flight.

9. auth from store appears unused in this snippet — unrelated to this diff but verify it's still needed after the import changes.

10. Global state mutation via window.open — popup blockers may block window.open if called after an async call (browser loses the "user gesture" context). Calling window.open synchronously and setting location afterwards is safer:

const win = window.open('', '_blank')
// ...after await...
win.location.href = accessUrl

Expand Down
Loading