Pre Merge pull request !134 from guo_ddt/master-fetch

This commit is contained in:
guo_ddt 2023-03-06 10:53:27 +00:00 committed by Gitee
commit c344f953ae
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -169,7 +169,24 @@ export const fetchRouteParams = () => {
*/
export const fetchRouteParamsLocation = () => {
try {
return document.location.hash.split('/').pop() || ''
// http://localhost:3000/#/chart/preview/792622755697790976?t=123
// 修正大屏预览界面添加query参数的时候ID获取异常。
const url = document.location.hash
const queryIndex = url.indexOf('?')
if (queryIndex > 0) {
const queryUrl = url.substring(queryIndex+1)
const queryParams = queryUrl.split('&')
// 并把参数放入sessionStorage后续动态接口可以使用
// 例如请求参数中使用javascript: return window.sessionStorage.getItem('t')
queryParams.forEach((str: string) => {
const kv = str.split('=')
if (kv.length === 2) window.sessionStorage.setItem(kv[0], kv[1])
})
const uri = url.substring(0, queryIndex)
return uri.split('/').pop() || ''
} else {
return url.split('/').pop() || ''
}
} catch (error) {
window['$message'].warning('查询路由信息失败,请联系管理员!')
return ''
@ -203,7 +220,7 @@ export const loginCheck = () => {
/**
* *
* @returns
* @returns
*/
export const previewPath = (id?: string | number) => {
const { origin, pathname } = document.location