diff --git a/src/layouts/components/AppsList.vue b/src/layouts/components/AppsList.vue index 780393c..3c3ab56 100644 --- a/src/layouts/components/AppsList.vue +++ b/src/layouts/components/AppsList.vue @@ -35,7 +35,6 @@ 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 @@ -64,10 +63,19 @@ export default { if (!item.appAddress) return ElMessage.error('缺少appAddress, 请联系管理员') const trxToken = getTrxToken() if (!trxToken) return ElMessage.error('缺少trxToken, 请联系管理员') - const params = { - token: getTrxToken() + let url = item.appAddress + const searchParams = 'token=' + trxToken + if (url.endsWith('?') || url.endsWith('&')) { + url += searchParams + } else if (url.indexOf('?') > -1) { + if (url.endsWith('&')) { + url += searchParams + } else { + url += '&' + searchParams + } + } else { + url += '?' + searchParams } - const url = appendParamsToUrl(item.appAddress, '', params) console.log('跳转应用时完整地址: ', url) window.open(url, '_blank') } diff --git a/src/utils/url.ts b/src/utils/url.ts deleted file mode 100644 index 85f61f0..0000000 --- a/src/utils/url.ts +++ /dev/null @@ -1,27 +0,0 @@ -export function appendParamsToUrl(url = '', pathname = '', 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的查询参数 - let result = urlObject.toString() - if (result.endsWith('?') || result.endsWith('&')) { - result += searchParams.toString() - } else if (result.indexOf('?') > -1) { - if (result.endsWith('&')) { - result += searchParams.toString() - } else { - result += '&' + searchParams.toString() - } - } else { - result += '?' + searchParams.toString() - } - // 返回处理后的URL字符串 - return result -}