fix: 修改拼接 url 的方式
parent
26e3d2ced0
commit
d95dc1ebcc
|
@ -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')
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue