From d95dc1ebcced1945d15c6684faf3beacd686d2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E5=90=AF=E9=BE=99?= Date: Sun, 1 Sep 2024 14:59:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=8B=BC=E6=8E=A5=20u?= =?UTF-8?q?rl=20=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/components/AppsList.vue | 8 +++++--- src/utils/url.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/utils/url.ts diff --git a/src/layouts/components/AppsList.vue b/src/layouts/components/AppsList.vue index 196e4fa..88c9012 100644 --- a/src/layouts/components/AppsList.vue +++ b/src/layouts/components/AppsList.vue @@ -35,6 +35,7 @@ import { ref } from 'vue' import { getTrxToken } from 'utils/auth' import { getAppList } from '@/services' import { ElMessage } from 'element-plus' +import { appendParamsToUrl } from 'utils/url.ts' let iconIndex = 1 const getAppIcon = () => { if (iconIndex > 9) iconIndex = 1 @@ -61,12 +62,13 @@ export default { const goPage = item => { if (item.enable != 1) return if (!item.appAddress) return ElMessage.error('缺少appAddress, 请联系管理员') - const url = new URL(item.appAddress) const trxToken = getTrxToken() if (!trxToken) return ElMessage.error('缺少trxToken, 请联系管理员') - console.log('跳转应用时携带的 token: ', trxToken) + const params = { + token: getTrxToken() + } + const url = appendParamsToUrl(item.appAddress, '', params) console.log('跳转应用时完整地址: ', url.toString()) - url.searchParams.append('token', trxToken) window.open(url.toString(), '_blank') } diff --git a/src/utils/url.ts b/src/utils/url.ts new file mode 100644 index 0000000..7e723ac --- /dev/null +++ b/src/utils/url.ts @@ -0,0 +1,18 @@ +export function appendParamsToUrl(url: string, pathname: string, params: Record) { + // 创建一个新的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() +}