过渡版:本地验发token
This commit is contained in:
1 parent
fb71def840
commit
a5f0ec645d
14 files changed
+313
-220
No files matched your search
@@ -19,6 +19,7 @@ import DeleteConfirmDialog from '../components/DeleteConfirmDialog.vue';
|
||||
import { loadReportLayoutPref, saveReportLayoutPref } from '../composables/useReportLayoutStorage';
|
||||
import { useGlobalMessageDialog } from '../composables/useGlobalMessageDialog';
|
||||
import { buildWecomAuditMeta, formatWecomAuditReason } from '../utils/wecom';
|
||||
import { getAuthHeaders } from '../utils/auth';
|
||||
import {
|
||||
ArrowLeft,
|
||||
// Save,
|
||||
@@ -748,29 +749,6 @@ const submitBatchPermission = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const getAuthHeaders = () => {
|
||||
let stored = localStorage.getItem('hxops_user');
|
||||
if (!stored) stored = sessionStorage.getItem('hxops_user');
|
||||
|
||||
if (!stored) return {};
|
||||
|
||||
try {
|
||||
const data = JSON.parse(stored);
|
||||
const user = data.user || data; // Handle both wrapped and unwrapped format
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
'X-Username': user.username,
|
||||
'X-Role': user.role,
|
||||
};
|
||||
if (user.id) {
|
||||
headers['X-User-Id'] = String(user.id);
|
||||
}
|
||||
return headers;
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 加载 Agent 列表
|
||||
* 核心逻辑:调用 GET /api/admin/agents
|
||||
@@ -1327,7 +1305,7 @@ const resetQuestionForm = () => {
|
||||
// 组件挂载时加载初始数据
|
||||
onMounted(async () => {
|
||||
const headers = getAuthHeaders();
|
||||
if (!headers['X-User-Id'] && !headers['X-Username']) {
|
||||
if (!headers['Authorization']) {
|
||||
console.warn('No auth headers found, redirecting to login');
|
||||
router.push('/');
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user