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

164 lines
4.7 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="概览">
2023-12-12 08:00:54 +00:00
<div class="main-calc-height p-24" style="min-width: 600px">
2023-11-24 06:49:25 +00:00
<h4 class="title-decoration-1 mb-16">应用信息</h4>
2023-12-08 08:55:29 +00:00
<el-card shadow="never" class="overview-card" v-loading="loading">
2023-11-24 06:49:25 +00:00
<div class="title flex align-center">
2023-12-01 07:59:50 +00:00
<AppAvatar
v-if="detail?.name"
:name="detail?.name"
pinyinColor
class="mr-12"
shape="square"
:size="32"
/>
2023-11-29 09:34:45 +00:00
<h4 class="ellipsis-1">{{ detail?.name }}</h4>
2023-11-24 06:49:25 +00:00
</div>
2023-12-05 03:36:11 +00:00
2023-12-07 07:57:00 +00:00
<el-row :gutter="12">
2023-12-12 08:00:54 +00:00
<el-col :span="12" class="mt-16">
2023-12-05 03:36:11 +00:00
<div class="flex">
<el-text type="info">公开访问链接</el-text>
2023-12-05 11:21:13 +00:00
<el-switch
2023-12-08 08:55:29 +00:00
v-model="accessToken.is_active"
2023-12-05 11:21:13 +00:00
class="ml-8"
size="small"
inline-prompt
active-text="开"
inactive-text="关"
2023-12-12 08:00:54 +00:00
@change="changeState($event)"
2023-12-05 11:21:13 +00:00
/>
2023-12-05 03:36:11 +00:00
</div>
2023-12-08 08:55:29 +00:00
<div class="mt-4 url-height">
2023-12-07 07:57:00 +00:00
<span class="vertical-middle lighter break-all">
2023-11-29 09:34:45 +00:00
{{ shareUrl }}
2023-11-24 06:49:25 +00:00
</span>
2023-11-30 10:50:42 +00:00
<el-button type="primary" text @click="copyClick(shareUrl)">
2023-12-01 03:36:04 +00:00
<AppIcon iconName="app-copy"></AppIcon>
2023-11-24 06:49:25 +00:00
</el-button>
2023-12-12 08:00:54 +00:00
<el-button @click="refreshAccessToken" type="primary" text style="margin-left: 1px">
2023-12-08 08:55:29 +00:00
<el-icon><RefreshRight /></el-icon>
</el-button>
2023-11-24 06:49:25 +00:00
</div>
2023-12-08 08:55:29 +00:00
<div>
2023-12-18 09:58:56 +00:00
<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>
2023-12-12 08:00:54 +00:00
<el-button :disabled="!accessToken?.is_active" @click="openDialog">
嵌入第三方
</el-button>
2023-12-05 03:36:11 +00:00
</div>
2023-11-24 06:49:25 +00:00
</el-col>
2023-12-12 08:00:54 +00:00
<el-col :span="12" class="mt-16">
2023-12-05 03:36:11 +00:00
<div class="flex">
<el-text type="info">API访问凭据</el-text>
</div>
2023-12-08 08:55:29 +00:00
<div class="mt-4 url-height">
2023-12-07 07:57:00 +00:00
<span class="vertical-middle lighter break-all">
2023-12-08 08:55:29 +00:00
{{ apiUrl }}
2023-11-24 06:49:25 +00:00
</span>
2023-12-08 08:55:29 +00:00
<el-button type="primary" text @click="copyClick(apiUrl)">
2023-12-05 03:36:11 +00:00
<AppIcon iconName="app-copy"></AppIcon>
2023-11-24 06:49:25 +00:00
</el-button>
</div>
2023-12-08 08:55:29 +00:00
<div>
<el-button @click="openAPIKeyDialog"> API Key </el-button>
2023-11-24 06:49:25 +00:00
</div>
2023-12-05 03:36:11 +00:00
</el-col>
2023-11-24 06:49:25 +00:00
</el-row>
</el-card>
</div>
2023-12-05 03:36:11 +00:00
<EmbedDialog ref="EmbedDialogRef" />
2023-12-08 08:55:29 +00:00
<APIKeyDialog ref="APIKeyDialogRef" />
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'
2023-11-29 09:34:45 +00:00
import { useRouter, useRoute } from 'vue-router'
2023-12-08 08:55:29 +00:00
import EmbedDialog from './component/EmbedDialog.vue'
import APIKeyDialog from './component/APIKeyDialog.vue'
2023-11-29 09:34:45 +00:00
import applicationApi from '@/api/application'
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'
2023-11-29 09:34:45 +00:00
import useStore from '@/stores'
const { application } = useStore()
const router = useRouter()
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'
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)
function refreshAccessToken() {
const obj = {
access_token_reset: true
}
const str = '刷新成功'
updateAccessToken(obj, str)
}
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)
})
}
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
})
}
onMounted(() => {
getDetail()
getAccessToken()
})
</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;
}
2023-12-08 08:55:29 +00:00
.url-height {
min-height: 50px;
}
2023-11-24 06:49:25 +00:00
}
</style>