From 0e379828f4793f52cae0e1ee2083a6657ef01185 Mon Sep 17 00:00:00 2001 From: lihui Date: Sun, 30 Nov 2025 14:18:03 +0800 Subject: [PATCH] =?UTF-8?q?fix=20:=20=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= =?UTF-8?q?=20=E5=88=87=E6=8D=A2=E9=A1=B5=E9=9D=A2500=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 15 ++++++++++++++- src/views/home.vue | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/router/index.js b/src/router/index.js index ac0a06d..6c7c276 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,6 +2,7 @@ import {createRouter, createWebHashHistory} from 'vue-router'; import {storeToRefs} from "pinia"; import {useAdminStore, useMessageStore} from "@/store/index.js"; import API from '@/util/http.js'; +import {ref} from "vue"; // 路由定义(包含权限映射 meta.permissionId) @@ -525,6 +526,7 @@ router.beforeEach(async (to, from, next) => { // 3. 正常跳转 next(); }); +const rawItems = ref([]) // 全局后置守卫:每次路由切换后执行 router.afterEach(async (to) => { // 接收to参数获取当前路由信息 @@ -532,13 +534,24 @@ router.afterEach(async (to) => { // 接收to参数获取当前路由信息 if (to.path === '/login') { return; } +// 1. 从localStorage获取数据(localStorage存储的是字符串,需解析) + const statusStr = localStorage.getItem('status'); + if (statusStr) { + // 示例:如果原始字符串是逗号分隔的格式(如 "1,2,3"),可按分隔符拆分后遍历 + rawItems.value = statusStr.split(','); // 根据实际格式调整分隔符 + rawItems.value.forEach((item, index) => { + console.log(`索引${index}:`, item.trim()); // trim() 去除空格(可选) + }); + } else { + console.log('localStorage中无status数据'); + } try { // 执行/getMessage请求 const newMessageRes = await API({ url: '/getMessage', method: 'POST', - data: {} + data: {status: rawItems.value} }); console.log('newMessageRes=======================:', newMessageRes.data) // 存入全局状态,供所有页面访问 diff --git a/src/views/home.vue b/src/views/home.vue index 91fa2d6..50cf584 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -189,6 +189,7 @@ const selectStatusById = () => { // 去重并返回结果(单一角色下实际不会有重复) return [...new Set(status)]; + }; console.log('权限测试',selectStatusById()); @@ -198,6 +199,8 @@ const getMessage = async () => { try { let params = {status: selectStatusById()}; + console.log('权限测试============',params); + localStorage.setItem('status',params.status) const res = await API({ url: '/getMessage', method: 'POST',