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',