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

271 lines
7.4 KiB
Vue
Raw Normal View History

2023-11-15 09:42:31 +00:00
<template>
2023-12-05 08:30:22 +00:00
<LayoutContainer header="概览">
2024-03-29 07:45:04 +00:00
<el-scrollbar>
<div class="main-calc-height p-24">
<h4 class="title-decoration-1 mb-16">应用信息</h4>
<el-card shadow="never" class="overview-card" v-loading="loading">
<div class="title flex align-center">
<AppAvatar
v-if="detail?.name"
:name="detail?.name"
pinyinColor
class="mr-12"
shape="square"
:size="32"
/>
<h4>{{ detail?.name }}</h4>
</div>
<el-row :gutter="12">
<el-col :span="12" class="mt-16">
<div class="flex">
<el-text type="info">公开访问链接</el-text>
<el-switch
v-model="accessToken.is_active"
class="ml-8"
size="small"
inline-prompt
active-text="开"
inactive-text="关"
@change="changeState($event)"
/>
</div>
<div class="mt-4 mb-16 url-height">
<span class="vertical-middle lighter break-all">
{{ 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">
<a v-if="accessToken?.is_active" :href="shareUrl" target="_blank"> </a>
<span v-else></span>
</el-button>
<el-button :disabled="!accessToken?.is_active" @click="openDialog">
嵌入第三方
</el-button>
<el-button @click="openLimitDialog"> 访 </el-button>
</div>
</el-col>
<el-col :span="12" class="mt-16">
<div class="flex">
<el-text type="info">API访问凭据</el-text>
</div>
<div class="mt-4 mb-16 url-height">
<span class="vertical-middle lighter break-all">
{{ apiUrl }}
</span>
<el-button type="primary" text @click="copyClick(apiUrl)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</div>
<div>
<el-button @click="openAPIKeyDialog"> API Key </el-button>
</div>
</el-col>
</el-row>
</el-card>
<h4 class="title-decoration-1 mt-16 mb-16">监控统计</h4>
<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="开始时间"
end-placeholder="结束时间"
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>
2023-12-05 03:36:11 +00:00
<EmbedDialog ref="EmbedDialogRef" />
2023-12-08 08:55:29 +00:00
<APIKeyDialog ref="APIKeyDialogRef" />
2024-03-12 10:55:50 +00:00
<LimitDialog ref="LimitDialogRef" @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">
2023-12-12 08:00:54 +00:00
import { ref, computed, onMounted } 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-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'
2024-03-29 07:45:04 +00:00
2023-11-30 10:50:42 +00:00
import { copyClick } from '@/utils/clipboard'
2023-11-29 09:34:45 +00:00
import useStore from '@/stores'
const { application } = useStore()
const route = useRoute()
2023-12-05 03:36:11 +00:00
const {
params: { id }
} = route as any
2023-12-08 08:55:29 +00:00
const apiUrl = window.location.origin + '/doc'
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)
2023-12-12 08:00:54 +00:00
const shareUrl = computed(() => application.location + accessToken.value.access_token)
2024-03-29 07:45:04 +00:00
const dayOptions = [
{
value: 7,
label: '过去7天'
},
{
value: 30,
label: '过去30天'
},
{
value: 90,
label: '过去90天'
},
{
value: 183,
label: '过去半年'
},
{
value: 'other',
label: '自定义'
}
]
const history_day = ref<number | string>(7)
// 日期组件时间
const daterangeValue = ref('')
// 提交日期时间
const daterange = ref({
start_time: '',
end_time: ''
})
const statisticsLoading = ref(false)
const statisticsData = ref([])
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(
`是否重新生成公开访问链接?`,
`重新生成公开访问链接会影响嵌入第三方脚本变更,需要将新脚本重新嵌入第三方,请谨慎操作!`,
{
confirmButtonText: '确认'
}
)
.then(() => {
const obj = {
access_token_reset: true
}
const str = '刷新成功'
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
}
const str = bool ? '启用成功' : '禁用成功'
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-03-12 10:55:50 +00:00
function refresh() {
getAccessToken()
}
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>