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

401 lines
12 KiB
Vue
Raw Normal View History

2023-11-15 09:42:31 +00:00
<template>
<LayoutContainer :header="$t('views.applicationOverview.title')">
2024-03-29 07:45:04 +00:00
<el-scrollbar>
<div class="main-calc-height p-24">
2024-07-22 10:52:56 +00:00
<h4 class="title-decoration-1 mb-16">
{{ $t('views.applicationOverview.appInfo.header') }}
</h4>
2024-03-29 07:45:04 +00:00
<el-card shadow="never" class="overview-card" v-loading="loading">
<div class="title flex align-center">
<div
class="edit-avatar mr-12"
@mouseenter="showEditIcon = true"
@mouseleave="showEditIcon = false"
>
<AppAvatar
v-if="isAppIcon(detail?.icon)"
shape="square"
:size="32"
style="background: none"
>
<img :src="detail?.icon" alt="" />
</AppAvatar>
<AppAvatar
v-else-if="detail?.name"
:name="detail?.name"
pinyinColor
shape="square"
:size="32"
/>
<AppAvatar
v-if="showEditIcon"
shape="square"
class="edit-mask"
:size="32"
@click="openEditAvatar"
>
<el-icon><EditPen /></el-icon>
</AppAvatar>
</div>
2024-03-29 07:45:04 +00:00
<h4>{{ detail?.name }}</h4>
</div>
<el-row :gutter="12">
2024-09-26 07:00:11 +00:00
<el-col :span="12" class="mt-16">
2024-03-29 07:45:04 +00:00
<div class="flex">
2024-07-22 10:52:56 +00:00
<el-text type="info">{{
$t('views.applicationOverview.appInfo.publicAccessLink')
}}</el-text>
2024-03-29 07:45:04 +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')"
2024-03-29 07:45:04 +00:00
@change="changeState($event)"
/>
</div>
2024-09-26 07:00:11 +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">
2024-03-29 07:45:04 +00:00
{{ shareUrl }}
</span>
<el-button type="primary" text @click="copyClick(shareUrl)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
<el-button @click="refreshAccessToken" type="primary" text style="margin-left: 1px">
<el-icon><RefreshRight /></el-icon>
</el-button>
</div>
<div>
<el-button :disabled="!accessToken?.is_active" type="primary">
2024-07-22 10:52:56 +00:00
<a v-if="accessToken?.is_active" :href="shareUrl" target="_blank">
{{ $t('views.applicationOverview.appInfo.demo') }}
</a>
<span v-else> {{ $t('views.applicationOverview.appInfo.demo') }}</span>
2024-03-29 07:45:04 +00:00
</el-button>
<el-button :disabled="!accessToken?.is_active" @click="openDialog">
2024-07-22 10:52:56 +00:00
{{ $t('views.applicationOverview.appInfo.embedThirdParty') }}
</el-button>
<el-button @click="openLimitDialog">
{{ $t('views.applicationOverview.appInfo.accessRestrictions') }}
</el-button>
<el-button @click="openDisplaySettingDialog">
{{ $t('views.applicationOverview.appInfo.displaySetting') }}
2024-03-29 07:45:04 +00:00
</el-button>
</div>
</el-col>
2024-09-26 07:00:11 +00:00
<el-col :span="12" class="mt-16">
2024-03-29 07:45:04 +00:00
<div class="flex">
2024-07-22 10:52:56 +00:00
<el-text type="info"
>{{ $t('views.applicationOverview.appInfo.apiAccessCredentials') }}
</el-text>
2024-03-29 07:45:04 +00:00
</div>
<div class="mt-4 mb-16 url-height">
<div>
<el-text>API 文档</el-text
><el-button
type="primary"
link
@click="toUrl(apiUrl)"
class="vertical-middle lighter break-all"
>
{{ apiUrl }}
</el-button>
</div>
2024-09-26 07:00:11 +00:00
<div class="flex align-center">
<span class="flex">
<el-text style="width: 80px">Base URL</el-text>
</span>
2024-10-09 06:19:23 +00:00
<span class="vertical-middle lighter break-all ellipsis-1">{{
baseUrl + id
}}</span>
2024-03-29 07:45:04 +00:00
<el-button type="primary" text @click="copyClick(baseUrl + id)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</div>
2024-03-29 07:45:04 +00:00
</div>
<div>
2024-07-22 10:52:56 +00:00
<el-button @click="openAPIKeyDialog">{{
$t('views.applicationOverview.appInfo.apiKey')
}}</el-button>
2024-03-29 07:45:04 +00:00
</div>
</el-col>
</el-row>
</el-card>
2024-07-22 10:52:56 +00:00
<h4 class="title-decoration-1 mt-16 mb-16">
{{ $t('views.applicationOverview.monitor.monitoringStatistics') }}
</h4>
2024-03-29 07:45:04 +00:00
<div class="mb-16">
<el-select v-model="history_day" class="mr-12 w-120" @change="changeDayHandle">
<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')"
2024-03-29 07:45:04 +00:00
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
@change="changeDayRangeHandle"
2023-12-01 07:59:50 +00:00
/>
2023-11-24 06:49:25 +00:00
</div>
2024-03-29 07:45:04 +00:00
<div v-loading="statisticsLoading">
<StatisticsCharts :data="statisticsData" />
</div>
</div>
</el-scrollbar>
2024-09-26 07:00:11 +00:00
<EmbedDialog
ref="EmbedDialogRef"
:data="detail"
:api-input-params="mapToUrlParams(apiInputParams)"
/>
2023-12-08 08:55:29 +00:00
<APIKeyDialog ref="APIKeyDialogRef" />
2024-03-12 10:55:50 +00:00
<LimitDialog ref="LimitDialogRef" @refresh="refresh" />
<EditAvatarDialog ref="EditAvatarDialogRef" @refresh="refreshIcon" />
2024-07-22 10:52:56 +00:00
<DisplaySettingDialog ref="DisplaySettingDialogRef" @refresh="refresh" />
2023-11-24 06:49:25 +00:00
</LayoutContainer>
2023-11-15 09:42:31 +00:00
</template>
2023-11-29 09:34:45 +00:00
<script setup lang="ts">
import { ref, computed, onMounted, watch } from 'vue'
2024-03-29 07:45:04 +00:00
import { useRoute } from 'vue-router'
2023-12-08 08:55:29 +00:00
import EmbedDialog from './component/EmbedDialog.vue'
import APIKeyDialog from './component/APIKeyDialog.vue'
2024-03-12 10:29:44 +00:00
import LimitDialog from './component/LimitDialog.vue'
2024-07-22 10:52:56 +00:00
import DisplaySettingDialog from './component/DisplaySettingDialog.vue'
import EditAvatarDialog from './component/EditAvatarDialog.vue'
2024-03-29 07:45:04 +00:00
import StatisticsCharts from './component/StatisticsCharts.vue'
2023-11-29 09:34:45 +00:00
import applicationApi from '@/api/application'
2024-03-29 07:45:04 +00:00
import overviewApi from '@/api/application-overview'
import { nowDate, beforeDay } from '@/utils/time'
2023-12-08 08:55:29 +00:00
import { MsgSuccess, MsgConfirm } from '@/utils/message'
2023-11-30 10:50:42 +00:00
import { copyClick } from '@/utils/clipboard'
import { isAppIcon } from '@/utils/application'
2023-11-29 09:34:45 +00:00
import useStore from '@/stores'
import { t } from '@/locales'
2023-11-29 09:34:45 +00:00
const { application } = useStore()
const route = useRoute()
2023-12-05 03:36:11 +00:00
const {
params: { id }
} = route as any
const apiUrl = window.location.origin + '/doc/chat/'
2023-12-08 08:55:29 +00:00
const baseUrl = window.location.origin + '/api/application/'
2024-07-22 10:52:56 +00:00
const DisplaySettingDialogRef = ref()
const EditAvatarDialogRef = ref()
2024-03-12 10:29:44 +00:00
const LimitDialogRef = ref()
2023-12-08 08:55:29 +00:00
const APIKeyDialogRef = ref()
2023-11-30 03:29:31 +00:00
const EmbedDialogRef = ref()
2023-12-12 08:00:54 +00:00
2023-12-08 08:55:29 +00:00
const accessToken = ref<any>({})
2023-11-29 09:34:45 +00:00
const detail = ref<any>(null)
const loading = ref(false)
2024-09-26 07:00:11 +00:00
const urlParams = computed(() =>
mapToUrlParams(apiInputParams.value) ? '?' + mapToUrlParams(apiInputParams.value) : ''
)
const shareUrl = computed(
() => application.location + accessToken.value.access_token + urlParams.value
)
2023-12-12 08:00:54 +00:00
2024-03-29 07:45:04 +00:00
const dayOptions = [
{
value: 7,
// @ts-ignore
2024-07-22 10:52:56 +00:00
label: t('views.applicationOverview.monitor.pastDayOptions.past7Days') // 使用 t 方法来国际化显示文本
2024-03-29 07:45:04 +00:00
},
{
value: 30,
label: t('views.applicationOverview.monitor.pastDayOptions.past30Days')
2024-03-29 07:45:04 +00:00
},
{
value: 90,
label: t('views.applicationOverview.monitor.pastDayOptions.past90Days')
2024-03-29 07:45:04 +00:00
},
{
value: 183,
label: t('views.applicationOverview.monitor.pastDayOptions.past183Days')
2024-03-29 07:45:04 +00:00
},
{
value: 'other',
label: t('views.applicationOverview.monitor.pastDayOptions.other')
2024-03-29 07:45:04 +00:00
}
]
const history_day = ref<number | string>(7)
// 日期组件时间
const daterangeValue = ref('')
// 提交日期时间
const daterange = ref({
start_time: '',
end_time: ''
})
const statisticsLoading = ref(false)
const statisticsData = ref([])
const showEditIcon = ref(false)
const apiInputParams = ref([])
function toUrl(url: string) {
window.open(url, '_blank')
}
2024-07-22 10:52:56 +00:00
function openDisplaySettingDialog() {
DisplaySettingDialogRef.value.open(accessToken.value)
}
function openEditAvatar() {
EditAvatarDialogRef.value.open(detail.value)
}
2024-03-29 07:45:04 +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() {
overviewApi.getStatistics(id, daterange.value, statisticsLoading).then((res: any) => {
statisticsData.value = res.data
})
}
2023-12-12 08:00:54 +00:00
function refreshAccessToken() {
MsgConfirm(
t('views.applicationOverview.appInfo.refreshToken.msgConfirm1'),
t('views.applicationOverview.appInfo.refreshToken.msgConfirm2'),
{
confirmButtonText: t('views.applicationOverview.appInfo.refreshToken.confirm'),
2024-07-22 10:52:56 +00:00
cancelButtonText: t('views.applicationOverview.appInfo.refreshToken.cancel')
}
)
.then(() => {
const obj = {
access_token_reset: true
}
2024-07-22 10:52:56 +00:00
// @ts-ignore
const str = t('views.applicationOverview.appInfo.refreshToken.refreshSuccess')
updateAccessToken(obj, str)
})
.catch(() => {})
2023-12-12 08:00:54 +00:00
}
2023-12-08 08:55:29 +00:00
function changeState(bool: Boolean) {
const obj = {
is_active: bool
}
2024-07-22 10:52:56 +00:00
const str = bool
? t('views.applicationOverview.appInfo.changeState.enableSuccess')
: t('views.applicationOverview.appInfo.changeState.disableSuccess')
2023-12-12 08:00:54 +00:00
updateAccessToken(obj, str)
}
function updateAccessToken(obj: any, str: string) {
2023-12-08 08:55:29 +00:00
applicationApi.putAccessToken(id as string, obj, loading).then((res) => {
2023-12-12 08:00:54 +00:00
accessToken.value = res?.data
2023-12-08 08:55:29 +00:00
MsgSuccess(str)
})
}
2024-03-12 10:55:50 +00:00
function openLimitDialog() {
LimitDialogRef.value.open(accessToken.value)
2024-03-12 10:29:44 +00:00
}
2023-12-08 08:55:29 +00:00
function openAPIKeyDialog() {
APIKeyDialogRef.value.open()
}
2023-11-30 03:29:31 +00:00
function openDialog() {
2023-12-08 08:55:29 +00:00
EmbedDialogRef.value.open(accessToken.value?.access_token)
2023-11-30 03:29:31 +00:00
}
2023-11-29 09:34:45 +00:00
function getAccessToken() {
2023-12-05 03:36:11 +00:00
application.asyncGetAccessToken(id, loading).then((res: any) => {
2023-12-08 08:55:29 +00:00
accessToken.value = res?.data
2023-11-29 09:34:45 +00:00
})
}
function getDetail() {
application.asyncGetApplicationDetail(id, loading).then((res: any) => {
detail.value = res.data
2024-09-26 07:00:11 +00:00
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) => {
return {
name: v.variable,
value: v.default_value
}
})
: v.properties.input_field_list
? v.properties.input_field_list
2024-09-26 07:00:11 +00:00
.filter((v: any) => v.assignment_method === 'api_input')
.map((v: any) => {
return {
name: v.variable,
value: v.default_value
}
})
: []
})
2023-11-29 09:34:45 +00:00
})
}
2024-03-12 10:55:50 +00:00
function refresh() {
getAccessToken()
}
function refreshIcon() {
getDetail()
}
function mapToUrlParams(map: any[]) {
2024-09-26 07:00:11 +00:00
const params = new URLSearchParams()
2024-09-26 07:00:11 +00:00
map.forEach((item: any) => {
params.append(encodeURIComponent(item.name), encodeURIComponent(item.value))
})
2024-09-26 07:00:11 +00:00
return params.toString() // 返回 URL 查询字符串
}
2023-11-29 09:34:45 +00:00
onMounted(() => {
getDetail()
getAccessToken()
2024-03-29 07:45:04 +00:00
changeDayHandle(history_day.value)
2023-11-29 09:34:45 +00:00
})
</script>
2023-11-24 06:49:25 +00:00
<style lang="scss" scoped>
.overview-card {
position: relative;
.active-button {
position: absolute;
right: 16px;
top: 21px;
}
}
</style>