mirror of
https://github.com/jumpserver/lina.git
synced 2026-05-18 21:54:29 +00:00
fix: Optimize URL generation in multiple components
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,6 +2,7 @@
|
||||
node_modules/
|
||||
dist/
|
||||
lina/
|
||||
ui/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
@@ -18,4 +19,4 @@ tests/**/coverage/
|
||||
.env.development
|
||||
.python-version
|
||||
|
||||
helper.json
|
||||
helper.json
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
<script>
|
||||
import Dialog from '@/components/Dialog/index.vue'
|
||||
import { encryptPassword } from '@/utils/secure'
|
||||
import { logout as redirectToLogout } from '@/utils/request'
|
||||
|
||||
export default {
|
||||
name: 'UserConfirmDialog',
|
||||
@@ -224,7 +225,7 @@ export default {
|
||||
})
|
||||
}, 500),
|
||||
logout() {
|
||||
window.location.href = `${process.env.VUE_APP_LOGOUT_PATH}?next=${this.$route.fullPath}`
|
||||
redirectToLogout()
|
||||
},
|
||||
sendCode() {
|
||||
this.$axios
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
|
||||
<script>
|
||||
import BaseFormatter from './base.vue'
|
||||
import { addBasePath } from '@/utils/common/index'
|
||||
|
||||
export default {
|
||||
name: 'AccountConnectFormatter',
|
||||
@@ -56,12 +57,12 @@ export default {
|
||||
can: () => true,
|
||||
getConnectUrl: (row, protocol, asset) => {
|
||||
const assetId = asset ? asset.id : row.asset.id
|
||||
return `/luna/admin-connect/?
|
||||
return addBasePath(`/luna/admin-connect/?
|
||||
asset=${assetId}
|
||||
&account=${row.id}
|
||||
&protocol=${protocol}
|
||||
&org_id=${this.$store.getters.currentOrg.id}
|
||||
`.replace(/\s+/g, '')
|
||||
`.replace(/\s+/g, ''))
|
||||
},
|
||||
asset: null,
|
||||
assetUrl: '/api/v1/assets/assets/{id}/',
|
||||
|
||||
@@ -46,7 +46,7 @@ Vue.prototype.$tr = key => {
|
||||
|
||||
export async function fetchTranslationsFromAPI() {
|
||||
try {
|
||||
const res = await axios.get(`${window.__BASE_PATH__}/api/v1/settings/i18n/lina/?lang=${lang}&flat=0`)
|
||||
const res = await axios.get(`/api/v1/settings/i18n/lina/?lang=${lang}&flat=0`)
|
||||
const data = res.data
|
||||
for (const key in data) {
|
||||
if (data.hasOwnProperty(key)) {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
|
||||
<script>
|
||||
import { mapGetters } from 'vuex'
|
||||
import { logout as redirectToLogout } from '@/utils/request'
|
||||
|
||||
export default {
|
||||
name: 'AccountDropdown',
|
||||
@@ -74,7 +75,7 @@ export default {
|
||||
if (currentOrg && (currentOrg.autoEnter || currentOrg.is_system)) {
|
||||
await this.$store.dispatch('users/setCurrentOrg', this.$store.getters.preOrg)
|
||||
}
|
||||
window.location.href = `${process.env.VUE_APP_LOGOUT_PATH}?next=${this.$route.fullPath}`
|
||||
redirectToLogout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import i18n from '@/i18n/i18n'
|
||||
import { message } from '@/utils/vue/message'
|
||||
import { scopedLocalStorage as localStorage } from '@/utils/storage'
|
||||
import { getBasePath, scopedLocalStorage as localStorage } from '@/utils/storage'
|
||||
|
||||
const _ = require('lodash')
|
||||
|
||||
@@ -194,6 +194,38 @@ export function newURL(url) {
|
||||
return obj
|
||||
}
|
||||
|
||||
export function addBasePath(path = '') {
|
||||
if (!path || /^https?:\/\//i.test(path)) {
|
||||
return path
|
||||
}
|
||||
|
||||
const basePath = getBasePath()
|
||||
const normalizedPath = path.startsWith('/') ? path : `/${path}`
|
||||
|
||||
if (!basePath) {
|
||||
return normalizedPath
|
||||
}
|
||||
|
||||
if (
|
||||
normalizedPath === basePath ||
|
||||
normalizedPath.startsWith(basePath + '/') ||
|
||||
normalizedPath.startsWith(basePath + '?') ||
|
||||
normalizedPath.startsWith(basePath + '#')
|
||||
) {
|
||||
return normalizedPath
|
||||
}
|
||||
|
||||
return `${basePath}${normalizedPath}`
|
||||
}
|
||||
|
||||
export function getCurrentPageUrl() {
|
||||
if (typeof window === 'undefined') {
|
||||
return '/'
|
||||
}
|
||||
const { pathname, search, hash } = window.location
|
||||
return `${pathname}${search}${hash}`
|
||||
}
|
||||
|
||||
export function getUpdateObjURL(url, objId) {
|
||||
const urlObj = new URL(url, location.origin)
|
||||
let pathname = urlObj.pathname
|
||||
@@ -231,7 +263,7 @@ export const assignIfNot = _.partialRight(_.assignInWith, customizer)
|
||||
|
||||
const scheme = document.location.protocol
|
||||
const port = document.location.port ? ':' + document.location.port : ''
|
||||
const BASE_URL = scheme + '//' + document.location.hostname + port
|
||||
const BASE_URL = scheme + '//' + document.location.hostname + port + getBasePath()
|
||||
|
||||
export function groupedDropdownToCascader(group) {
|
||||
const firstType = group[0]
|
||||
@@ -427,7 +459,7 @@ export function openNewWindow(url) {
|
||||
let params = 'toolbar=yes,scrollbars=yes,resizable=yes'
|
||||
params = params + `,top=${top},left=${left},width=${screen.width / 3},height=${screen.height / 3}`
|
||||
window.sessionStorage.setItem('newWindowCount', `${count + 1}`)
|
||||
window.open(url, '_blank', params)
|
||||
window.open(addBasePath(url), '_blank', params)
|
||||
}
|
||||
|
||||
export function getDrawerWidth() {
|
||||
@@ -548,8 +580,10 @@ export function randomString(length, includeSymbols = false) {
|
||||
}
|
||||
|
||||
export function createWsUrl(path) {
|
||||
if (/^wss?:\/\//i.test(path)) {
|
||||
return path
|
||||
}
|
||||
const scheme = location.protocol === 'https:' ? 'wss' : 'ws'
|
||||
const port = location.port ? ':' + location.port : ''
|
||||
const base = window.__BASE_PATH__ || ''
|
||||
return scheme + '://' + location.hostname + port + base + path
|
||||
return scheme + '://' + location.hostname + port + addBasePath(path)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ function openOrReuseWindow(
|
||||
export function openTaskPage(taskId, taskType, taskUrl) {
|
||||
taskType = taskType || 'celery'
|
||||
if (!taskUrl) {
|
||||
taskUrl = `${window.__BASE_PATH__}/core/ops/${taskType}/task/${taskId}/log/?type=${taskType}`
|
||||
taskUrl = `/core/ops/${taskType}/task/${taskId}/log/?type=${taskType}`
|
||||
}
|
||||
openOrReuseWindow(taskUrl)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import axios from 'axios'
|
||||
import i18n from '@/i18n/i18n'
|
||||
import { eventBus } from '@/utils/vue/eventbus'
|
||||
import { getTokenFromCookie } from '@/utils/jms/auth'
|
||||
import { getErrorResponseMsg } from '@/utils/common'
|
||||
import { addBasePath, getCurrentPageUrl, getErrorResponseMsg } from '@/utils/common'
|
||||
import { MessageBox } from 'element-ui'
|
||||
import { message } from '@/utils/vue/message'
|
||||
import store from '@/store'
|
||||
@@ -70,9 +70,8 @@ service.interceptors.request.use(
|
||||
|
||||
function goToLogin() {
|
||||
setTimeout(() => {
|
||||
const base = window.__BASE_PATH__ || ''
|
||||
const next = base ? window.location.pathname.replace(base, '') : window.location.pathname
|
||||
window.location = `${base}${process.env.VUE_APP_LOGIN_PATH}?next=${next}`
|
||||
const next = encodeURIComponent(getCurrentPageUrl())
|
||||
window.location = `${addBasePath(process.env.VUE_APP_LOGIN_PATH)}?next=${next}`
|
||||
}, 200)
|
||||
localStorage.setItem('next', window.location.hash.replace('#', ''))
|
||||
}
|
||||
@@ -114,9 +113,8 @@ function ifBadRequest({ response, error }) {
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
const base = window.__BASE_PATH__ || ''
|
||||
const next = base ? location.pathname.replace(base, '') : location.pathname
|
||||
window.location.href = `${base}${process.env.VUE_APP_LOGOUT_PATH}?next=${next}`
|
||||
const next = encodeURIComponent(getCurrentPageUrl())
|
||||
window.location.href = `${addBasePath(process.env.VUE_APP_LOGOUT_PATH)}?next=${next}`
|
||||
}
|
||||
|
||||
export function flashErrorMsg({ response, error }) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
import DetailCard from '@/components/Cards/DetailCard/index'
|
||||
import { QuickActions } from '@/components'
|
||||
import { terminateSession } from '@/api/sessions'
|
||||
import { addBasePath } from '@/utils/common'
|
||||
import { toSafeLocalDateStr } from '@/utils/common/time'
|
||||
import TwoCol from '@/layout/components/Page/TwoColPage.vue'
|
||||
|
||||
@@ -70,7 +71,7 @@ export default {
|
||||
click: function() {
|
||||
// 跳转到luna页面
|
||||
const joinUrl = '/luna/monitor/' + vm.session.id
|
||||
window.open(joinUrl, 'height=600, width=800, top=400, left=400, toolbar=no, menubar=no, scrollbars=no, location=no, status=no')
|
||||
window.open(addBasePath(joinUrl), 'height=600, width=800, top=400, left=400, toolbar=no, menubar=no, scrollbars=no, location=no, status=no')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,7 +90,7 @@ export default {
|
||||
callbacks: {
|
||||
click: function() {
|
||||
const replayUrl = '/luna/replay/' + vm.session.id
|
||||
window.open(replayUrl)
|
||||
window.open(addBasePath(replayUrl))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<script>
|
||||
import BaseList from './BaseList'
|
||||
import { download } from '@/utils/common/index'
|
||||
import { addBasePath, download } from '@/utils/common/index'
|
||||
|
||||
export default {
|
||||
name: 'OfflineList',
|
||||
@@ -30,7 +30,7 @@ export default {
|
||||
callback: function({ row, tableData }) {
|
||||
// 跳转到luna页面
|
||||
const replayUrl = '/luna/replay/' + row.id
|
||||
window.open(replayUrl)
|
||||
window.open(addBasePath(replayUrl))
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<script>
|
||||
import BaseList from './BaseList'
|
||||
import { terminateSession, toggleLockSession } from '@/api/sessions'
|
||||
import { addBasePath } from '@/utils/common/index'
|
||||
import { IsSupportPauseSessionType } from '@/utils/jms/index'
|
||||
|
||||
export default {
|
||||
@@ -97,7 +98,7 @@ export default {
|
||||
},
|
||||
callback: function({ row, tableData }) {
|
||||
const monitorUrl = '/luna/monitor/' + row.id
|
||||
window.open(monitorUrl, '_blank', 'height=600, width=850, top=400, left=400, toolbar=no, menubar=no, scrollbars=no, location=no, status=no')
|
||||
window.open(addBasePath(monitorUrl), '_blank', 'height=600, width=850, top=400, left=400, toolbar=no, menubar=no, scrollbars=no, location=no, status=no')
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
<script type="text/jsx">
|
||||
import { ChoicesFormatter, DetailFormatter, SwitchFormatter } from '@/components/Table/TableFormatters'
|
||||
import { BASE_URL } from '@/utils/common/index'
|
||||
import { DrawerListTable as ListTable } from '@/components'
|
||||
|
||||
export default {
|
||||
@@ -141,7 +140,7 @@ export default {
|
||||
type: 'primary',
|
||||
can: this.$hasPerm('ops.view_taskmonitor'),
|
||||
callback: () => {
|
||||
window.open(`${BASE_URL}/core/flower/?_=${Date.now()}`,)
|
||||
window.open(`/core/flower/?_=${Date.now()}`,)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
|
||||
<script>
|
||||
import IBox from '@/components/Common/IBox'
|
||||
import { addBasePath } from '@/utils/common/index'
|
||||
import { IsSupportPauseSessionType } from '@/utils/jms/index'
|
||||
|
||||
export default {
|
||||
@@ -138,7 +139,7 @@ export default {
|
||||
},
|
||||
onMonitor() {
|
||||
const joinUrl = `/luna/monitor/${this.session.id}?ticket_id=${this.object.id}`
|
||||
window.open(joinUrl, '_blank', 'height=600, width=850, top=400, left=400, toolbar=no, menubar=no, scrollbars=no, location=no, status=no')
|
||||
window.open(addBasePath(joinUrl), '_blank', 'height=600, width=850, top=400, left=400, toolbar=no, menubar=no, scrollbars=no, location=no, status=no')
|
||||
},
|
||||
onToggleLock() {
|
||||
const url = '/api/v1/terminal/tasks/toggle-lock-session-for-ticket/'
|
||||
|
||||
@@ -16,7 +16,7 @@ import GrantedAssets from '@/components/Apps/GrantedAssets/index.vue'
|
||||
import Page from '@/layout/components/Page/index.vue'
|
||||
import { EditableInputFormatter } from '@/components/Table/TableFormatters'
|
||||
import { getPreference } from '@/api/settings'
|
||||
import { openNewWindow } from '@/utils/common/index'
|
||||
import { addBasePath, openNewWindow } from '@/utils/common/index'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@@ -49,7 +49,7 @@ export default {
|
||||
openNewWindow(url)
|
||||
} else {
|
||||
const url = `/luna/?login_to=${row.id}${oid ? `&oid=${oid}` : ''}`
|
||||
window.open(url, '_blank')
|
||||
window.open(addBasePath(url), '_blank')
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<script>
|
||||
import HomeCard from './HomeCard.vue'
|
||||
import { getPreference } from '@/api/settings'
|
||||
import { openNewWindow } from '@/utils/common/index'
|
||||
import { addBasePath, openNewWindow } from '@/utils/common/index'
|
||||
|
||||
export default {
|
||||
name: 'Announcement',
|
||||
@@ -79,7 +79,7 @@ export default {
|
||||
if (this.preference?.basic?.connect_default_open_method === 'new') {
|
||||
openNewWindow(`/luna/connect?login_to=${row.asset_id}&login_account=${row.account_id}`)
|
||||
} else {
|
||||
window.open(`/luna/?login_to=${row.asset_id}&login_account=${row.account_id}`, '_blank')
|
||||
window.open(addBasePath(`/luna/?login_to=${row.asset_id}&login_account=${row.account_id}`), '_blank')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user