feat: 监控和日志 iframe 修改

develop
时启龙 2024-09-01 14:56:37 +08:00
parent 7306736fa6
commit 4944aec150
4 changed files with 65 additions and 23 deletions

View File

@ -0,0 +1,18 @@
export function appendParamsToUrl(url: string, pathname: string, params: Record<string, string>) {
// 创建一个新的URL对象在末尾添加 pathname
const urlObject = new URL(pathname, url)
// 获取该URL的查询参数对象
const searchParams = new URLSearchParams(urlObject.search)
// 添加新的参数
for (const key in params) {
searchParams.append(key, params[key])
}
// 设置URL的查询参数
urlObject.search = searchParams.toString()
// 返回处理后的URL字符串
return urlObject.toString()
}

View File

@ -1,31 +1,43 @@
<template>
<div>
<div v-if="iframeUrl">
<iframe :src="iframeUrl" frameborder="0" class="iframe-box"></iframe>
</div>
</template>
<script>
import { getToken } from '@cmp/cmp-element'
function addParamsToUrl(url, params) {
const queryString = Object.keys(params)
.map(key => key + '=' + params[key])
.join('&')
// url
const separator = url.includes('?') ? '&' : '?'
return url + separator + queryString
}
import { appendParamsToUrl } from '@cmp/cmp-common/utils/url.ts'
import { getSystemTreeConfigs } from '@cmp/cmp-api/system'
export default {
data() {
return {
url: ''
}
},
created() {
this.getUrl()
},
computed: {
// , [] , params
iframeUrl() {
if (!this.url) return ''
const params = {
token: getToken(),
...(this.$route.query || {})
}
const url = addParamsToUrl(this.$route.meta.url, params)
const url = appendParamsToUrl(this.url, this.$route.path, params)
console.log('iframeUrl: ', url.toString())
return url.toString()
}
},
methods: {
async getUrl() {
const res = await getSystemTreeConfigs({ category: '系统对接' })
if (res.success) {
this.url = (res.data.find(item => item.name === '日志管理系统')?.values || []).find(({ code }) => code === 'LOGURL')?.value || ''
}
}
}
}
</script>

View File

@ -1,3 +1,3 @@
export default {
OmsDashbaord: () => import('views/iframe.vue')
LogIframe: () => import('views/iframe.vue')
}

View File

@ -1,31 +1,43 @@
<template>
<div>
<div v-if="iframeUrl">
<iframe :src="iframeUrl" frameborder="0" class="iframe-box"></iframe>
</div>
</template>
<script>
import { getToken } from '@cmp/cmp-element'
function addParamsToUrl(url, params) {
const queryString = Object.keys(params)
.map(key => key + '=' + params[key])
.join('&')
// url
const separator = url.includes('?') ? '&' : '?'
return url + separator + queryString
}
import { appendParamsToUrl } from '@cmp/cmp-common/utils/url.ts'
import { getSystemTreeConfigs } from '@cmp/cmp-api/system'
export default {
data() {
return {
url: ''
}
},
created() {
this.getUrl()
},
computed: {
// , [] , params
iframeUrl() {
if (!this.url) return ''
const params = {
token: getToken(),
...(this.$route.query || {})
}
const url = addParamsToUrl(this.$route.meta.url, params)
const url = appendParamsToUrl(this.url, this.$route.path, params)
console.log('iframeUrl: ', url.toString())
return url.toString()
}
},
methods: {
async getUrl() {
const res = await getSystemTreeConfigs({ category: '系统对接' })
if (res.success) {
this.url = (res.data.find(item => item.name === '基础监控系统')?.values || []).find(({ code }) => code === 'MONITORURL')?.value || ''
}
}
}
}
</script>