From 365c4c9d697a64a87543ffa06b6c1eec7082d7c1 Mon Sep 17 00:00:00 2001 From: lilinyuan <1084668738@qq.com> Date: Sun, 24 Mar 2024 23:00:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/permisstion.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/stores/permisstion.js b/src/stores/permisstion.js index 5733e3d..ddf9255 100644 --- a/src/stores/permisstion.js +++ b/src/stores/permisstion.js @@ -43,14 +43,6 @@ export const usePermisstionStroe = defineStore('permisstion', () => { route.component = loadView(route.component) } } - if (route.pathParams != null) { - let pathParams = route.pathParams - route.pathParams = JSON.parse(route.pathParams) - route.query = {} - for (const key in route.pathParams) { - route.query = {[key]: route.pathParams[key]} - } - } if (route.children !== null && route.children && route.children.length !== 0) { route.children = formatAsyncRouters(route.children) } @@ -69,12 +61,32 @@ export const usePermisstionStroe = defineStore('permisstion', () => { if (item.children && item.children.length !== 0) { generateMenu(item.children) } + if (item.pathParams != null) { + item.path = formatPath(item.path, JSON.parse(item.pathParams)) + } item.title = item.meta.title item.icon = item.meta.icon return true }) } + // 拼接地址 + const formatPath = (path, query) => { + const queryArr = [] + let newPath = path + for (const key in query) { + queryArr.push({label: key, value: query[key]}) + } + queryArr.forEach((item, index)=>{ + if(!index) { + newPath += `?${item.label}=${item.value}` + } else { + newPath += `&${item.label}=${item.value}` + } + }) + return newPath + } + const loadView = (view) => { if (import.meta.env.MODE === 'development') {