补充修改

This commit is contained in:
2025-10-11 08:53:47 +08:00
parent 1a1abf4c26
commit 9b8d177e34
34 changed files with 391 additions and 1882 deletions

View File

@@ -338,7 +338,7 @@ const routes = [
]
const router = createRouter({
history: createWebHistory(),
history: createWebHistory('/government/'), // 设置基础路径
routes
})

View File

@@ -123,10 +123,10 @@ const captchaUrl = ref('')
// 表单数据
const formData = reactive({
username: 'admin',
password: '123456',
username: '',
password: '',
captcha: '',
remember: true
remember: false
})
// 表单验证规则
@@ -212,20 +212,7 @@ onMounted(() => {
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
&::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image:
radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
radial-gradient(circle at 40% 40%, rgba(120, 119, 198, 0.2) 0%, transparent 50%);
}
background: #f5f5f5;
.background-overlay {
position: absolute;
@@ -233,7 +220,7 @@ onMounted(() => {
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.1);
background: rgba(0, 0, 0, 0.02);
}
}

View File

@@ -1,65 +0,0 @@
// 测试行政人员管理API接口
import axios from 'axios';
// 创建axios实例
const instance = axios.create({
baseURL: 'http://localhost:5352/api',
timeout: 10000,
headers: {
'Content-Type': 'application/json'
}
});
// 登录获取token
const login = async () => {
try {
const response = await instance.post('/auth/login', {
username: 'admin',
password: '123456'
});
console.log('登录成功获取到token');
return response.data.token;
} catch (error) {
console.error('登录失败:', error.message);
throw error;
}
};
// 测试获取行政人员列表
const testGetAdminStaffList = async (token) => {
try {
instance.defaults.headers.common['Authorization'] = `Bearer ${token}`;
const response = await instance.get('/personnel');
console.log('\n获取行政人员列表成功:');
console.log('- 状态码:', response.status);
console.log('- 返回数据结构:', Object.keys(response.data));
console.log('- 行政人员总数:', response.data.total);
console.log('- 返回的行政人员列表长度:', response.data.data.length);
if (response.data.data.length > 0) {
console.log('- 第一条行政人员数据:', response.data.data[0]);
}
return response.data;
} catch (error) {
console.error('获取行政人员列表失败:', error.message);
throw error;
}
};
// 主测试函数
const runTests = async () => {
console.log('开始测试行政人员管理API...');
try {
// 1. 登录获取token
const token = await login();
// 2. 测试获取行政人员列表
await testGetAdminStaffList(token);
console.log('\n所有测试完成');
} catch (error) {
console.error('测试失败:', error);
}
};
// 运行测试
runTests();

View File

@@ -1,152 +0,0 @@
// 前端组件API测试脚本 - ES模块格式
import axios from 'axios';
// 创建axios实例
const instance = axios.create({
baseURL: 'http://localhost:5352/api',
timeout: 10000,
headers: {
'Content-Type': 'application/json'
}
});
// 登录获取token
async function login() {
try {
const response = await instance.post('/auth/login', {
username: 'admin',
password: '123456'
});
console.log('登录成功:', response.data);
// 修正token获取路径 - 正确路径是response.data.data.token
return response.data.data?.token || null;
} catch (error) {
console.error('登录失败:', error);
console.error('错误详情:', error.response?.data || error.message);
return null;
}
}
// 测试获取行政人员列表
async function testGetAdminStaffList(token) {
try {
const response = await instance.get('/personnel', {
headers: {
'Authorization': `Bearer ${token}`
},
params: {
page: 1,
pageSize: 10
}
});
console.log('行政人员列表获取成功:');
console.log('- 数据结构:', Object.keys(response.data));
console.log('- 行政人员总数:', response.data.total);
console.log('- 行政人员列表数据长度:', response.data.data?.length || 0);
if (response.data.data && response.data.data.length > 0) {
console.log('- 第一条数据示例:', response.data.data[0]);
}
return response.data;
} catch (error) {
console.error('行政人员列表获取失败:', error);
console.error('错误详情:', error.response?.data || error.message);
return null;
}
}
// 测试获取部门列表
async function testGetDepartmentsList(token) {
try {
const response = await instance.get('/government/departments', {
headers: {
'Authorization': `Bearer ${token}`
}
});
console.log('部门列表获取成功:');
console.log('- 数据结构:', Object.keys(response.data));
console.log('- 部门列表数据长度:', response.data.data?.length || 0);
if (response.data.data && response.data.data.length > 0) {
console.log('- 第一条数据示例:', response.data.data[0]);
}
return response.data;
} catch (error) {
console.error('部门列表获取失败:', error);
console.error('错误详情:', error.response?.data || error.message);
return null;
}
}
// 测试获取岗位列表
async function testGetPositionsList(token) {
try {
const response = await instance.get('/government/positions', {
headers: {
'Authorization': `Bearer ${token}`
}
});
console.log('岗位列表获取成功:');
console.log('- 数据结构:', Object.keys(response.data));
console.log('- 岗位列表数据长度:', response.data.data?.length || 0);
if (response.data.data && response.data.data.length > 0) {
console.log('- 第一条数据示例:', response.data.data[0]);
}
return response.data;
} catch (error) {
console.error('岗位列表获取失败:', error);
console.error('错误详情:', error.response?.data || error.message);
return null;
}
}
// 主测试函数 - 模拟AdminStaff组件的初始化流程
async function runComponentTest() {
console.log('开始模拟AdminStaff组件初始化测试...');
// 1. 登录获取token
console.log('\n1. 登录认证');
const token = await login();
if (!token) {
console.error('测试失败: 无法获取登录token');
return;
}
// 2. 测试获取部门列表 - 对应组件中的fetchDepartments()
console.log('\n2. 获取部门列表');
const departmentsData = await testGetDepartmentsList(token);
// 3. 测试获取岗位列表 - 对应组件中的fetchPositions()
console.log('\n3. 获取岗位列表');
const positionsData = await testGetPositionsList(token);
// 4. 测试获取行政人员列表 - 对应组件中的fetchAdminStaffList()
console.log('\n4. 获取行政人员列表');
const staffListData = await testGetAdminStaffList(token);
console.log('\n测试完成!');
console.log('----------------------------------------');
console.log('测试结果总结:');
console.log('- 登录:', token ? '成功' : '失败');
console.log('- 部门列表:', departmentsData ? '成功' : '失败');
console.log('- 岗位列表:', positionsData ? '成功' : '失败');
console.log('- 行政人员列表:', staffListData ? '成功' : '失败');
// 分析可能的组件渲染问题
if (staffListData && departmentsData && positionsData) {
console.log('\n所有API调用成功但页面仍显示空白可能的原因:');
console.log('1. 数据格式不匹配 - 检查返回数据结构是否与组件期望的一致');
console.log('2. 组件生命周期问题 - 检查onMounted中是否正确调用initData()');
console.log('3. 数据处理逻辑错误 - 检查staffData.value的赋值和转换逻辑');
console.log('4. 权限问题 - 检查用户角色和权限是否正确');
console.log('5. 前端控制台错误 - 检查浏览器控制台是否有详细错误信息');
} else {
console.log('\nAPI调用失败是页面空白的可能原因请检查:');
console.log('1. 后端接口是否正确实现');
console.log('2. 认证token是否有效');
console.log('3. 网络连接是否正常');
}
}
// 运行测试
runComponentTest().catch(err => {
console.error('测试过程中发生错误:', err);
});

View File

@@ -1,52 +0,0 @@
// 从前端目录测试API访问
const axios = require('axios');
// 创建axios实例使用与前端相同的配置
const api = axios.create({
baseURL: 'http://localhost:5352/api',
timeout: 5000,
headers: {
'Content-Type': 'application/json'
}
});
async function testApi() {
try {
console.log('开始从前端目录测试API...');
// 测试行政人员列表API
console.log('\n测试行政人员列表API:');
const adminStaffResponse = await api.get('/government/admin-staff');
console.log(`✅ 行政人员列表API调用成功返回${adminStaffResponse.data.length}条数据`);
// 测试部门列表API
console.log('\n测试部门列表API:');
const departmentResponse = await api.get('/government/departments');
console.log(`✅ 部门列表API调用成功返回${departmentResponse.data.length}条数据`);
// 测试岗位列表API
console.log('\n测试岗位列表API:');
const positionResponse = await api.get('/government/positions');
console.log(`✅ 岗位列表API调用成功返回${positionResponse.data.length}条数据`);
// 测试带有查询参数的API
console.log('\n测试带查询参数的API:');
const filteredResponse = await api.get('/government/admin-staff?page=1&pageSize=3');
console.log(`✅ 带查询参数的API调用成功返回${filteredResponse.data.length}条数据`);
console.log('\n✅ 所有API测试成功完成');
} catch (error) {
console.error('❌ API测试失败:', error.message);
if (error.response) {
console.error('错误状态码:', error.response.status);
console.error('错误数据:', error.response.data);
} else if (error.request) {
console.error('没有收到响应:', error.request);
} else {
console.error('请求配置错误:', error.message);
}
console.error('错误详情:', error);
}
}
testApi();

View File

@@ -1,13 +0,0 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/svg+xml" href="/vite.svg">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TextArea 测试页面</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/test-main.js"></script>
</body>
</html>

View File

@@ -1,86 +0,0 @@
// 测试前端认证修复效果的脚本
import axios from 'axios';
import fs from 'fs';
import path from 'path';
// 配置
const BASE_URL = 'http://localhost:5352/api';
const USERNAME = 'admin';
const PASSWORD = '123456';
// 测试函数
async function runTest() {
console.log('===== 开始测试智慧耳标页面认证问题 =====');
try {
// 1. 尝试登录获取token
console.log('1. 尝试登录...');
const loginResponse = await axios.post(`${BASE_URL}/auth/login`, {
username: USERNAME,
password: PASSWORD
});
if (loginResponse.data && loginResponse.data.token) {
const token = loginResponse.data.token;
console.log('登录成功获取到token:', token);
// 2. 使用获取的token尝试访问智能耳标API
console.log('2. 使用token访问智能耳标API...');
const headers = { 'Authorization': `Bearer ${token}` };
const smartEarmarkResponse = await axios.get(`${BASE_URL}/smart-earmark`, { headers });
console.log('智能耳标API访问成功返回状态:', smartEarmarkResponse.status);
console.log('返回数据示例:', JSON.stringify(smartEarmarkResponse.data.slice(0, 1), null, 2));
console.log('\n===== 测试成功!智慧耳标页面认证问题已修复 =====');
} else {
console.error('登录失败未获取到token:', loginResponse.data);
// 如果后端使用模拟数据我们也创建一个模拟token来测试
console.log('\n3. 尝试使用模拟token访问API适用于前端模拟登录场景...');
const mockToken = 'mock-jwt-token-' + Date.now();
const headers = { 'Authorization': `Bearer ${mockToken}` };
try {
const smartEarmarkResponse = await axios.get(`${BASE_URL}/smart-earmark`, {
headers,
timeout: 5000
});
console.log('使用模拟token访问成功状态:', smartEarmarkResponse.status);
} catch (error) {
console.error('使用模拟token访问失败:', error.code || error.message);
if (error.response) {
console.error('错误详情:', error.response.status, error.response.data);
}
// 记录问题以便后续分析
const errorInfo = {
timestamp: new Date().toISOString(),
error: error.message,
response: error.response ? {
status: error.response.status,
data: error.response.data
} : null
};
fs.writeFileSync(
path.join(__dirname, 'auth_error.log'),
JSON.stringify(errorInfo, null, 2) + '\n',
{ flag: 'a' }
);
}
}
} catch (error) {
console.error('测试过程中发生错误:', error.message);
if (error.response) {
console.error('错误状态码:', error.response.status);
console.error('错误详情:', error.response.data);
} else if (error.request) {
console.error('未收到响应:', error.request);
console.error('请检查后端服务是否正常运行在端口5352');
}
}
}
// 运行测试
runTest();

View File

@@ -1,66 +0,0 @@
// 简化的测试脚本专门验证智慧耳标API访问
import axios from 'axios';
// 配置
const API_BASE_URL = 'http://localhost:5352/api';
const TEST_USERNAME = 'admin';
const TEST_PASSWORD = '123456';
// 创建axios实例
const apiClient = axios.create({
baseURL: API_BASE_URL,
timeout: 10000,
headers: {
'Content-Type': 'application/json',
},
});
// 测试函数
async function testEarmarkApi() {
try {
console.log('===== 开始测试智慧耳标API =====');
// 1. 尝试登录获取真实token
console.log('1. 登录获取token...');
const loginResponse = await apiClient.post('/auth/login', {
username: TEST_USERNAME,
password: TEST_PASSWORD
});
if (loginResponse.status === 200 && loginResponse.data.code === 200) {
const token = loginResponse.data.data.token;
console.log('登录成功获取到token');
// 2. 使用获取的token访问智慧耳标API
console.log('2. 使用token访问智慧耳标API...');
apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;
const earmarkResponse = await apiClient.get('/smart-earmark');
if (earmarkResponse.status === 200) {
console.log('智慧耳标API访问成功');
console.log('响应状态码:', earmarkResponse.status);
console.log('数据总量:', earmarkResponse.data.data?.length || '无数据');
console.log('\n===== 测试成功 =====');
console.log('修复总结:');
console.log('1. 前端修复了api.js中缺失的message组件导入');
console.log('2. 前端修复了authStore中认证状态判断问题');
console.log('3. 后端修复了auth.js中JWT验证相关的导入问题');
console.log('4. 后端:修复了重复声明的变量问题');
console.log('\n结论点击智慧耳标页面自动退出到登录页的问题已解决');
} else {
console.error('智慧耳标API访问失败状态码:', earmarkResponse.status);
}
} else {
console.error('登录失败:', loginResponse.data?.message || '未知错误');
}
} catch (error) {
console.error('测试过程中发生错误:', error.message);
if (error.response) {
console.error('错误详情:', error.response.status, error.response.data);
}
}
}
// 运行测试
testEarmarkApi();

View File

@@ -4,6 +4,7 @@ import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
base: '/government/', // 设置基础路径
resolve: {
alias: {
'@': '/src',
@@ -18,5 +19,18 @@ export default defineConfig({
changeOrigin: true
}
}
},
build: {
outDir: 'dist',
assetsDir: 'assets',
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vendor: ['vue', 'vue-router', 'ant-design-vue'],
echarts: ['echarts', 'vue-echarts']
}
}
}
}
})