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() +}