|
|
|
@ -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) |
|
|
|
// 存入全局状态,供所有页面访问
|
|
|
|
|