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

466 lines
15 KiB
Vue
Raw Normal View History

2025-06-03 08:08:49 +00:00
<template>
2025-06-10 09:57:33 +00:00
<div class="p-16-24">
<h2 class="mb-16">{{ $t('views.applicationOverview.title') }}</h2>
2025-06-03 08:08:49 +00:00
<el-scrollbar>
2025-06-10 09:57:33 +00:00
<div class="main-calc-height">
<el-card style="--el-card-padding: 24px">
<h4 class="title-decoration-1 mb-16">
{{ $t('views.applicationOverview.appInfo.header') }}
</h4>
<el-card shadow="never" class="overview-card" v-loading="loading">
<div class="title flex align-center">
2025-07-10 11:16:47 +00:00
<div class="edit-avatar mr-12">
2025-07-02 13:49:55 +00:00
<el-avatar shape="square" :size="32" style="background: none">
2025-07-10 11:16:47 +00:00
<img :src="resetUrl(detail?.icon, resetUrl('./favicon.ico'))" alt="" />
2025-06-10 09:57:33 +00:00
</el-avatar>
2025-06-03 08:08:49 +00:00
</div>
2025-06-10 09:57:33 +00:00
<h4>{{ detail?.name || '-' }}</h4>
</div>
<el-row :gutter="12">
<el-col :span="12" class="mt-16">
<div class="flex">
2025-07-10 11:16:47 +00:00
<el-text type="info"
>{{ $t('views.applicationOverview.appInfo.publicAccessLink') }}
</el-text>
2025-06-10 09:57:33 +00:00
<el-switch
v-model="accessToken.is_active"
class="ml-8"
size="small"
inline-prompt
:active-text="$t('views.applicationOverview.appInfo.openText')"
:inactive-text="$t('views.applicationOverview.appInfo.closeText')"
:before-change="() => changeState(accessToken.is_active)"
/>
2025-06-03 08:08:49 +00:00
</div>
2025-06-10 09:57:33 +00:00
<div class="mt-4 mb-16 url-height flex align-center" style="margin-bottom: 37px">
<span class="vertical-middle lighter break-all ellipsis-1">
{{ shareUrl }}
</span>
2025-06-03 08:08:49 +00:00
<el-tooltip effect="dark" :content="$t('common.copy')" placement="top">
2025-06-10 09:57:33 +00:00
<el-button type="primary" text @click="copyClick(shareUrl)">
2025-06-03 08:08:49 +00:00
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
2025-06-10 09:57:33 +00:00
<el-tooltip effect="dark" :content="$t('common.refresh')" placement="top">
<el-button
@click="refreshAccessToken"
type="primary"
text
style="margin-left: 1px"
>
<el-icon>
2025-07-10 11:16:47 +00:00
<RefreshRight />
</el-icon>
2025-06-10 09:57:33 +00:00
</el-button>
</el-tooltip>
2025-06-03 08:08:49 +00:00
</div>
2025-06-10 09:57:33 +00:00
<div>
<el-button
v-if="accessToken?.is_active"
:disabled="!accessToken?.is_active"
tag="a"
:href="shareUrl"
target="_blank"
>
<AppIcon iconName="app-create-chat" class="mr-4"></AppIcon>
{{ $t('views.application.operation.toChat') }}
</el-button>
<el-button v-else :disabled="!accessToken?.is_active">
<AppIcon iconName="app-create-chat" class="mr-4"></AppIcon>
{{ $t('views.application.operation.toChat') }}
</el-button>
2025-06-19 03:46:52 +00:00
<el-button
:disabled="!accessToken?.is_active"
@click="openDialog"
2025-06-25 09:18:47 +00:00
v-if="permissionPrecise.overview_embed(id)"
2025-06-18 12:22:33 +00:00
>
2025-06-10 09:57:33 +00:00
<AppIcon iconName="app-export" class="mr-4"></AppIcon>
{{ $t('views.applicationOverview.appInfo.embedInWebsite') }}
</el-button>
2025-06-19 03:46:52 +00:00
<!-- 访问限制 -->
2025-07-01 02:28:26 +00:00
<el-button @click="openLimitDialog" v-if="permissionPrecise.overview_access(id)">
<el-icon class="mr-4">
2025-07-10 11:16:47 +00:00
<Lock />
</el-icon>
2025-06-10 09:57:33 +00:00
{{ $t('views.applicationOverview.appInfo.accessControl') }}
</el-button>
2025-06-19 03:46:52 +00:00
<!-- 显示设置 -->
<el-button
@click="openDisplaySettingDialog"
2025-06-25 09:18:47 +00:00
v-if="permissionPrecise.overview_display(id)"
2025-06-18 12:22:33 +00:00
>
<el-icon class="mr-4">
2025-07-10 11:16:47 +00:00
<Setting />
</el-icon>
2025-06-10 09:57:33 +00:00
{{ $t('views.applicationOverview.appInfo.displaySetting') }}
</el-button>
</div>
</el-col>
<el-col :span="12" class="mt-16">
<div class="flex">
<el-text type="info"
2025-07-10 11:16:47 +00:00
>{{ $t('views.applicationOverview.appInfo.apiAccessCredentials') }}
2025-06-10 09:57:33 +00:00
</el-text>
</div>
<div class="mt-4 mb-16 url-height">
<div>
2025-07-10 11:16:47 +00:00
<el-text>API {{ $t('common.fileUpload.document') }} </el-text>
<el-button
2025-06-10 09:57:33 +00:00
type="primary"
link
@click="toUrl(apiUrl)"
class="vertical-middle lighter break-all"
>
{{ apiUrl }}
</el-button>
</div>
<div class="flex align-center">
<span class="flex">
<el-text style="width: 80px">Base URL</el-text>
</span>
<span class="vertical-middle lighter break-all ellipsis-1">{{
2025-07-10 11:16:47 +00:00
baseUrl + id
}}</span>
2025-06-10 09:57:33 +00:00
<el-tooltip effect="dark" :content="$t('common.copy')" placement="top">
<el-button type="primary" text @click="copyClick(baseUrl + id)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
</div>
</div>
<div>
2025-06-19 03:46:52 +00:00
<el-button
@click="openAPIKeyDialog"
2025-06-25 09:18:47 +00:00
v-if="permissionPrecise.overview_api_key(id)"
2025-06-18 12:22:33 +00:00
>
<el-icon class="mr-4">
2025-07-10 11:16:47 +00:00
<Key />
</el-icon>
{{ $t('views.applicationOverview.appInfo.apiKey') }}
2025-07-10 11:16:47 +00:00
</el-button>
2025-06-10 09:57:33 +00:00
</div>
</el-col>
</el-row>
</el-card>
2025-06-03 08:08:49 +00:00
</el-card>
2025-06-10 09:57:33 +00:00
<el-card style="--el-card-padding: 24px" class="mt-16">
<h4 class="title-decoration-1 mb-16">
{{ $t('views.applicationOverview.monitor.monitoringStatistics') }}
</h4>
<div class="mb-16">
<el-select
v-model="history_day"
class="mr-12"
@change="changeDayHandle"
style="width: 180px"
>
<el-option
v-for="item in dayOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
<el-date-picker
v-if="history_day === 'other'"
v-model="daterangeValue"
type="daterange"
:start-placeholder="$t('views.applicationOverview.monitor.startDatePlaceholder')"
:end-placeholder="$t('views.applicationOverview.monitor.endDatePlaceholder')"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
@change="changeDayRangeHandle"
2025-06-03 08:08:49 +00:00
/>
2025-06-10 09:57:33 +00:00
</div>
<div v-loading="statisticsLoading">
2025-07-10 11:16:47 +00:00
<StatisticsCharts :data="statisticsData" />
2025-06-10 09:57:33 +00:00
</div>
</el-card>
2025-06-03 08:08:49 +00:00
</div>
</el-scrollbar>
2025-06-10 09:57:33 +00:00
2025-06-03 08:08:49 +00:00
<EmbedDialog
ref="EmbedDialogRef"
:data="detail"
:api-input-params="mapToUrlParams(apiInputParams)"
/>
2025-07-10 11:16:47 +00:00
<APIKeyDialog ref="APIKeyDialogRef" />
2025-06-19 03:46:52 +00:00
<!-- 社区版访问限制 -->
2025-07-10 11:16:47 +00:00
<component :is="currentLimitDialog" ref="LimitDialogRef" @refresh="refresh" />
2025-06-19 03:46:52 +00:00
<!-- 显示设置 -->
2025-07-10 11:16:47 +00:00
<component :is="currentDisplaySettingDialog" ref="DisplaySettingDialogRef" @refresh="refresh" />
2025-06-10 09:57:33 +00:00
</div>
2025-06-03 08:08:49 +00:00
</template>
<script setup lang="ts">
2025-07-10 11:16:47 +00:00
import { ref, computed, onMounted, shallowRef, nextTick } from 'vue'
import { useRoute } from 'vue-router'
2025-06-03 08:08:49 +00:00
import EmbedDialog from './component/EmbedDialog.vue'
import APIKeyDialog from './component/APIKeyDialog.vue'
import LimitDialog from './component/LimitDialog.vue'
2025-06-19 03:46:52 +00:00
import XPackLimitDrawer from './xpack-component/XPackLimitDrawer.vue'
2025-06-03 08:08:49 +00:00
import DisplaySettingDialog from './component/DisplaySettingDialog.vue'
2025-06-19 03:46:52 +00:00
import XPackDisplaySettingDialog from './xpack-component/XPackDisplaySettingDialog.vue'
2025-06-03 08:08:49 +00:00
import StatisticsCharts from './component/StatisticsCharts.vue'
2025-06-03 09:29:33 +00:00
import applicationApi from '@/api/application/application'
2025-07-10 11:16:47 +00:00
import { nowDate, beforeDay } from '@/utils/time'
import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { copyClick } from '@/utils/clipboard'
import { isAppIcon, resetUrl } from '@/utils/common'
import { mapToUrlParams } from '@/utils/application'
2025-06-03 08:08:49 +00:00
import useStore from '@/stores'
2025-07-10 11:16:47 +00:00
import { t } from '@/locales'
import { EditionConst } from '@/utils/permission/data'
import { hasPermission } from '@/utils/permission/index'
2025-06-25 09:18:47 +00:00
import permissionMap from '@/permission'
2025-06-03 08:08:49 +00:00
const route = useRoute()
2025-06-25 09:18:47 +00:00
const apiType = computed<'workspace'>(() => {
2025-07-01 02:28:26 +00:00
return 'workspace'
2025-06-25 09:18:47 +00:00
})
const permissionPrecise = computed(() => {
return permissionMap['application'][apiType.value]
})
2025-07-10 11:16:47 +00:00
const { user, application } = useStore()
2025-06-03 08:08:49 +00:00
const {
2025-07-10 11:16:47 +00:00
params: { id },
2025-06-03 08:08:49 +00:00
} = route as any
const apiUrl = window.location.origin + '/doc/chat/'
2025-07-10 11:16:47 +00:00
const baseUrl = window.location.origin + `${window.MaxKB.chatPrefix}/api/`
2025-06-03 08:08:49 +00:00
const APIKeyDialogRef = ref()
const EmbedDialogRef = ref()
const accessToken = ref<any>({})
const detail = ref<any>(null)
const loading = ref(false)
const urlParams = computed(() =>
2025-06-10 09:57:33 +00:00
mapToUrlParams(apiInputParams.value) ? '?' + mapToUrlParams(apiInputParams.value) : '',
2025-06-03 08:08:49 +00:00
)
const shareUrl = computed(
2025-07-02 06:30:41 +00:00
() => `${window.location.origin}/chat/` + accessToken.value?.access_token + urlParams.value,
2025-06-03 08:08:49 +00:00
)
const dayOptions = [
{
value: 7,
// @ts-ignore
2025-06-10 09:57:33 +00:00
label: t('views.applicationOverview.monitor.pastDayOptions.past7Days'),
2025-06-03 08:08:49 +00:00
},
{
value: 30,
2025-06-10 09:57:33 +00:00
label: t('views.applicationOverview.monitor.pastDayOptions.past30Days'),
2025-06-03 08:08:49 +00:00
},
{
value: 90,
2025-06-10 09:57:33 +00:00
label: t('views.applicationOverview.monitor.pastDayOptions.past90Days'),
2025-06-03 08:08:49 +00:00
},
{
value: 183,
2025-06-10 09:57:33 +00:00
label: t('views.applicationOverview.monitor.pastDayOptions.past183Days'),
2025-06-03 08:08:49 +00:00
},
{
value: 'other',
2025-06-26 13:13:43 +00:00
label: t('common.custom'),
2025-06-10 09:57:33 +00:00
},
2025-06-03 08:08:49 +00:00
]
const history_day = ref<number | string>(7)
// 日期组件时间
const daterangeValue = ref('')
// 提交日期时间
const daterange = ref({
start_time: '',
2025-06-10 09:57:33 +00:00
end_time: '',
2025-06-03 08:08:49 +00:00
})
const statisticsLoading = ref(false)
const statisticsData = ref([])
const showEditIcon = ref(false)
const apiInputParams = ref([])
function toUrl(url: string) {
window.open(url, '_blank')
}
2025-06-19 03:46:52 +00:00
// 显示设置
const DisplaySettingDialogRef = ref()
const currentDisplaySettingDialog = shallowRef<any>(null)
2025-06-03 08:08:49 +00:00
function openDisplaySettingDialog() {
2025-06-19 03:46:52 +00:00
// 企业版和专业版
if (hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')) {
currentDisplaySettingDialog.value = XPackDisplaySettingDialog
} else {
// 社区版
currentDisplaySettingDialog.value = DisplaySettingDialog
}
nextTick(() => {
2025-06-19 09:25:46 +00:00
if (currentDisplaySettingDialog.value == XPackDisplaySettingDialog) {
applicationApi.getApplicationSetting(id).then((ok) => {
DisplaySettingDialogRef.value?.open(ok.data, detail.value)
})
} else {
DisplaySettingDialogRef.value?.open(accessToken.value, detail.value)
}
2025-06-19 03:46:52 +00:00
})
2025-06-03 08:08:49 +00:00
}
2025-06-19 03:46:52 +00:00
// 访问限制
const LimitDialogRef = ref()
const currentLimitDialog = shallowRef<any>(null)
2025-06-19 03:46:52 +00:00
function openLimitDialog() {
// 企业版和专业版
if (hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')) {
currentLimitDialog.value = XPackLimitDrawer
} else {
// 社区版
currentLimitDialog.value = LimitDialog
}
nextTick(() => {
LimitDialogRef.value.open(accessToken.value)
})
}
2025-06-03 08:08:49 +00:00
function changeDayHandle(val: number | string) {
if (val !== 'other') {
daterange.value.start_time = beforeDay(val)
daterange.value.end_time = nowDate
getAppStatistics()
}
}
function changeDayRangeHandle(val: string) {
daterange.value.start_time = val[0]
daterange.value.end_time = val[1]
getAppStatistics()
}
function getAppStatistics() {
2025-06-10 12:07:14 +00:00
applicationApi.getStatistics(id, daterange.value, statisticsLoading).then((res: any) => {
2025-06-03 08:08:49 +00:00
statisticsData.value = res.data
})
}
function refreshAccessToken() {
MsgConfirm(
t('views.applicationOverview.appInfo.refreshToken.msgConfirm1'),
t('views.applicationOverview.appInfo.refreshToken.msgConfirm2'),
{
confirmButtonText: t('common.confirm'),
2025-06-10 09:57:33 +00:00
cancelButtonText: t('common.cancel'),
},
2025-06-03 08:08:49 +00:00
)
.then(() => {
const obj = {
2025-06-10 09:57:33 +00:00
access_token_reset: true,
2025-06-03 08:08:49 +00:00
}
// @ts-ignore
const str = t('views.applicationOverview.appInfo.refreshToken.refreshSuccess')
updateAccessToken(obj, str)
})
2025-07-10 11:16:47 +00:00
.catch(() => {})
2025-06-03 08:08:49 +00:00
}
2025-07-10 14:33:39 +00:00
async function changeState(bool: boolean) {
2025-06-03 08:08:49 +00:00
const obj = {
2025-06-10 09:57:33 +00:00
is_active: !bool,
2025-06-03 08:08:49 +00:00
}
const str = obj.is_active ? t('common.status.enableSuccess') : t('common.status.disableSuccess')
2025-07-10 14:33:39 +00:00
await updateAccessToken(obj, str)
2025-06-03 08:08:49 +00:00
.then(() => {
return true
})
.catch(() => {
return false
})
}
async function updateAccessToken(obj: any, str: string) {
applicationApi.putAccessToken(id as string, obj, loading).then((res) => {
accessToken.value = res?.data
MsgSuccess(str)
})
}
function openAPIKeyDialog() {
APIKeyDialogRef.value.open()
}
2025-06-03 08:08:49 +00:00
function openDialog() {
EmbedDialogRef.value.open(accessToken.value?.access_token)
}
2025-06-03 08:08:49 +00:00
function getAccessToken() {
application.asyncGetAccessToken(id, loading).then((res: any) => {
accessToken.value = res?.data
})
}
function getDetail() {
application.asyncGetApplicationDetail(id, loading).then((res: any) => {
detail.value = res.data
detail.value.work_flow?.nodes
?.filter((v: any) => v.id === 'base-node')
.map((v: any) => {
apiInputParams.value = v.properties.api_input_field_list
? v.properties.api_input_field_list.map((v: any) => {
2025-07-10 11:16:47 +00:00
return {
name: v.variable,
value: v.default_value,
}
})
2025-06-03 08:08:49 +00:00
: v.properties.input_field_list
? v.properties.input_field_list
2025-07-10 11:16:47 +00:00
.filter((v: any) => v.assignment_method === 'api_input')
.map((v: any) => {
return {
name: v.variable,
value: v.default_value,
}
})
2025-06-03 08:08:49 +00:00
: []
})
})
}
function refresh() {
getAccessToken()
}
function refreshIcon() {
getDetail()
}
onMounted(() => {
2025-06-11 08:38:48 +00:00
getDetail()
getAccessToken()
changeDayHandle(history_day.value)
2025-06-03 08:08:49 +00:00
})
</script>
<style lang="scss" scoped>
.overview-card {
position: relative;
2025-06-03 08:08:49 +00:00
.active-button {
position: absolute;
right: 16px;
top: 21px;
}
}
</style>