refactor:基础静态路由路径使用的字面量改为变量

This commit is contained in:
妙码生花 2023-10-23 09:29:38 +08:00
parent 085b5fd62c
commit 873e47c52b
5 changed files with 10 additions and 6 deletions

View File

@ -30,6 +30,7 @@ import useCurrentInstance from '/@/utils/useCurrentInstance'
import Contextmenu from '/@/components/contextmenu/index.vue'
import horizontalScroll from '/@/utils/horizontalScroll'
import { getFirstRoute, routePush } from '/@/utils/router'
import { adminBaseRoutePath } from '/@/router/static/adminBase'
const route = useRoute()
const router = useRouter()
@ -97,7 +98,7 @@ const toLastTab = () => {
if (lastTab) {
router.push(lastTab)
} else {
router.push('/admin')
router.push(adminBaseRoutePath)
}
}

View File

@ -5,6 +5,7 @@ import { defineStore } from 'pinia'
import { STORE_TAB_VIEW_CONFIG } from '/@/stores/constant/cacheKey'
import type { NavTabs } from '/@/stores/interface/index'
import type { RouteLocationNormalized, RouteRecordRaw } from 'vue-router'
import { adminBaseRoutePath } from '/@/router/static/adminBase'
export const useNavTabs = defineStore(
'navTabs',
@ -101,7 +102,7 @@ export const useNavTabs = defineStore(
function encodeRoutesURI(data: RouteRecordRaw[]) {
data.forEach((item) => {
if (item.meta?.menu_type == 'iframe') {
item.path = '/admin/iframe/' + encodeURIComponent(item.path)
item.path = adminBaseRoutePath + '/iframe/' + encodeURIComponent(item.path)
}
if (item.children && item.children.length) {

View File

@ -155,10 +155,11 @@ export const buildJsonToElTreeData = (data: any): ElTreeData[] => {
* @param path path
*/
export const isAdminApp = (path = '') => {
const regex = new RegExp(`^${adminBaseRoutePath}`)
if (path) {
return /^\/admin/.test(path)
return regex.test(path)
}
if (/^\/admin/.test(getCurrentRoutePath())) {
if (regex.test(getCurrentRoutePath())) {
return true
}
return false

View File

@ -247,7 +247,7 @@ export const addRouteItem = (viewsComponent: Record<string, any>, route: any, pa
let path = '',
component
if (route.menu_type == 'iframe') {
path = (isAdminApp() ? '/admin' : '/user') + '/iframe/' + encodeURIComponent(route.url)
path = (isAdminApp() ? adminBaseRoute.path : memberCenterBaseRoute.path) + '/iframe/' + encodeURIComponent(route.url)
component = () => import('/@/layouts/common/router-view/iframe.vue')
} else {
path = parentName ? route.path : '/' + route.path

View File

@ -11,7 +11,7 @@
</div>
<el-button
v-if="memberCenter.state.open"
@click="$router.push('/user')"
@click="$router.push(memberCenterBaseRoutePath)"
class="container-button"
color="#ffffff"
size="large"
@ -35,6 +35,7 @@ import { useSiteConfig } from '/@/stores/siteConfig'
import { useMemberCenter } from '/@/stores/memberCenter'
import Header from '/@/layouts/frontend/components/header.vue'
import Footer from '/@/layouts/frontend/components/footer.vue'
import { memberCenterBaseRoutePath } from '/@/router/static/memberCenterBase'
const siteConfig = useSiteConfig()
const memberCenter = useMemberCenter()