From 4647caf3836468b79cc755858e90b09609dc8eba Mon Sep 17 00:00:00 2001 From: MTrun <1262327911@qq.com> Date: Tue, 21 Dec 2021 15:56:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=BC=96=E8=BE=91=E5=92=8C?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E7=9A=84=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/enums/pageEnum.ts | 2 +- src/utils/page.ts | 61 ++++++++++++++++--- .../project/items/components/Card/index.vue | 12 +++- .../components/List/hooks/useModal.hook.ts | 15 +++-- .../project/items/components/List/index.vue | 17 ++++-- src/views/project/templateMarket/index.vue | 44 ++++++++----- 6 files changed, 117 insertions(+), 34 deletions(-) diff --git a/src/enums/pageEnum.ts b/src/enums/pageEnum.ts index b311eca6..f1e1f562 100644 --- a/src/enums/pageEnum.ts +++ b/src/enums/pageEnum.ts @@ -2,7 +2,7 @@ import { ResultEnum } from '@/enums/httpEnum' export enum ChartEnum { // 图表创建 - CHART_HOME = '/chart/home/:id', + CHART_HOME = '/chart/home/:id(.*)*', CHART_HOME_NAME = 'ChartHome', } diff --git a/src/utils/page.ts b/src/utils/page.ts index 3a0393e3..101dd999 100644 --- a/src/utils/page.ts +++ b/src/utils/page.ts @@ -1,18 +1,23 @@ import { ResultEnum } from '@/enums/httpEnum' import { ErrorPageNameMap, PageEnum } from '@/enums/pageEnum' +import { RouteLocation } from 'vue-router' import router from '@/router' import { docPath, giteeSourceCodePath } from '@/settings/pathConst' /** * * 根据名字跳转路由 * @param pageName + * @param isReplace + * @param windowOpen */ -export const routerTurnByName = (pageName: string, isReplace?: boolean, windowOpen?: boolean) => { +export const routerTurnByName = ( + pageName: string, + isReplace?: boolean, + windowOpen?: boolean +) => { if (windowOpen) { - const path = router.resolve({ - name: pageName - }) - openNewWindow(path.href) + const path = fetchPathByName(pageName, 'href') + openNewWindow(path) return } if (isReplace) { @@ -26,6 +31,49 @@ export const routerTurnByName = (pageName: string, isReplace?: boolean, windowOp }) } +/** + * * 根据名称获取路由信息 + * @param pageName + * @param pageName + */ +export const fetchPathByName = (pageName: string, p?: string) => { + const pathData = router.resolve({ + name: pageName + }) + return p ? (pathData as any)[p] : pathData +} + +/** + * * 根据路径跳转路由 + * @param { String } path + * @param { Array } query + * @param isReplace + */ +export const routerTurnByPath = ( + path: string, + query?: Array, + isReplace?: boolean, + windowOpen?: boolean +) => { + let fullPath = '' + if (query?.length) { + fullPath = `${path}/${query.join('/')}` + } + if (windowOpen) { + openNewWindow(fullPath) + return + } + if (isReplace) { + router.replace({ + path: fullPath + }) + return + } + router.push({ + path: fullPath + }) +} + /** * * 错误页重定向 * @param icon @@ -49,7 +97,7 @@ export const logout = () => { * * 新开页面 * @param url */ - export const openNewWindow = (url: string) => { +export const openNewWindow = (url: string) => { window.open(url, 'blank') } @@ -68,4 +116,3 @@ export const openDoc = () => { export const openGiteeSourceCode = () => { openNewWindow(giteeSourceCodePath) } - diff --git a/src/views/project/items/components/Card/index.vue b/src/views/project/items/components/Card/index.vue index 50f2cf26..5edea524 100644 --- a/src/views/project/items/components/Card/index.vue +++ b/src/views/project/items/components/Card/index.vue @@ -60,7 +60,7 @@