Browse Source

fix : 消息推送 切换页面500错误

huangqizheng/feature-20251213090502-现金退款多语言
lihui 1 month ago
parent
commit
0e379828f4
  1. 15
      src/router/index.js
  2. 3
      src/views/home.vue

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

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

Loading…
Cancel
Save