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> <template>
<div> <div v-if="iframeUrl">
<iframe :src="iframeUrl" frameborder="0" class="iframe-box"></iframe> <iframe :src="iframeUrl" frameborder="0" class="iframe-box"></iframe>
</div> </div>
</template> </template>
<script> <script>
import { getToken } from '@cmp/cmp-element' import { getToken } from '@cmp/cmp-element'
function addParamsToUrl(url, params) { import { appendParamsToUrl } from '@cmp/cmp-common/utils/url.ts'
const queryString = Object.keys(params) import { getSystemTreeConfigs } from '@cmp/cmp-api/system'
.map(key => key + '=' + params[key])
.join('&')
// url
const separator = url.includes('?') ? '&' : '?'
return url + separator + queryString
}
export default { export default {
data() {
return {
url: ''
}
},
created() {
this.getUrl()
},
computed: { computed: {
// , [] , params
iframeUrl() { iframeUrl() {
if (!this.url) return ''
const params = { const params = {
token: getToken(), token: getToken(),
...(this.$route.query || {}) ...(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() 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> </script>

View File

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

View File

@ -1,31 +1,43 @@
<template> <template>
<div> <div v-if="iframeUrl">
<iframe :src="iframeUrl" frameborder="0" class="iframe-box"></iframe> <iframe :src="iframeUrl" frameborder="0" class="iframe-box"></iframe>
</div> </div>
</template> </template>
<script> <script>
import { getToken } from '@cmp/cmp-element' import { getToken } from '@cmp/cmp-element'
function addParamsToUrl(url, params) { import { appendParamsToUrl } from '@cmp/cmp-common/utils/url.ts'
const queryString = Object.keys(params) import { getSystemTreeConfigs } from '@cmp/cmp-api/system'
.map(key => key + '=' + params[key])
.join('&')
// url
const separator = url.includes('?') ? '&' : '?'
return url + separator + queryString
}
export default { export default {
data() {
return {
url: ''
}
},
created() {
this.getUrl()
},
computed: { computed: {
// , [] , params
iframeUrl() { iframeUrl() {
if (!this.url) return ''
const params = { const params = {
token: getToken(), token: getToken(),
...(this.$route.query || {}) ...(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() 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> </script>