完善项目

This commit is contained in:
xuqiuyun
2025-09-28 17:58:43 +08:00
parent ec3f472641
commit 5b615473e0
59 changed files with 5428 additions and 593 deletions

View File

@@ -1,4 +1,4 @@
# 生产环境配置
VITE_API_BASE_URL=/api
VITE_API_FULL_URL=https://ad.ningmuyun.com/api
VITE_API_FULL_URL=https://ad.ningmuyun.com/farm/api
VITE_USE_PROXY=false

View File

@@ -19,13 +19,18 @@ server {
access_log off;
}
# 处理Vue Router的history模式
location / {
try_files $uri $uri/ /index.html;
# 处理Vue Router的history模式 - 支持/farm/路径
location /farm/ {
try_files $uri $uri/ /farm/index.html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# 根路径重定向到/farm/
location = / {
return 301 /farm/;
}
# API代理到后端服务
location /api/ {

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>重定向中...</title>
<script>
// 立即重定向到正确的路径
window.location.href = '/farm/login';
</script>
</head>
<body>
<p>正在重定向到登录页面...</p>
<p>如果没有自动跳转,请点击 <a href="/farm/login">这里</a></p>
</body>
</html>

View File

@@ -4,7 +4,7 @@ import routes from './routes'
// 创建路由实例
const router = createRouter({
history: createWebHistory(),
history: createWebHistory('/farm/'),
routes,
scrollBehavior(to, from, savedPosition) {
// 如果有保存的位置,则恢复到保存的位置
@@ -30,6 +30,12 @@ router.beforeEach(async (to, from, next) => {
return
}
// 处理根路径访问,重定向到仪表盘
if (to.path === '/') {
next('/dashboard')
return
}
// 如果访问登录页面且已有有效token重定向到仪表盘
if (to.path === '/login' && userStore.token && userStore.isLoggedIn) {
const redirectPath = to.query.redirect || '/dashboard'

View File

@@ -31,7 +31,7 @@
</div>
<div class="stat-content">
<div class="stat-value">{{ stats.highTemperature }}</div>
<div class="stat-label">预警</div>
<div class="stat-label">温度预警</div>
</div>
</div>
<div class="stat-card">
@@ -392,7 +392,7 @@ const getAlertTypeText = (type) => {
'movement': '异常运动预警',
'wear': '佩戴异常预警'
}
return typeMap[type] || '未知预警'
return typeMap[type] || '温度预警'
}
// 获取预警类型颜色

View File

@@ -204,6 +204,7 @@ import { message } from 'ant-design-vue'
import { SearchOutlined, ExportOutlined } from '@ant-design/icons-vue'
import { ExportUtils } from '../utils/exportUtils'
import { loadBMapScript, createMap } from '@/utils/mapService'
import { API_CONFIG } from '@/config/env.js'
// 响应式数据
const hosts = ref([])
@@ -312,8 +313,8 @@ const fetchData = async (showMessage = false) => {
console.log('搜索条件:', searchValue.value.trim())
}
// 调用API获取智能主机数据
const apiUrl = `/api/smart-devices/hosts?${params}`
// 调用API获取智能主机数据使用环境配置的基础URL兼容生产 /farm/api 前缀)
const apiUrl = `${API_CONFIG.baseUrl}/smart-devices/hosts?${params}`
console.log('API请求URL:', apiUrl)
const response = await fetch(apiUrl, {
@@ -610,8 +611,8 @@ const exportData = async () => {
console.log('导出搜索条件:', searchValue.value.trim())
}
// 调用API获取所有智能主机数据
const apiUrl = `/api/smart-devices/hosts?${params}`
// 调用API获取所有智能主机数据使用环境配置的基础URL兼容生产 /farm/api 前缀)
const apiUrl = `${API_CONFIG.baseUrl}/smart-devices/hosts?${params}`
console.log('导出API请求URL:', apiUrl)
const response = await fetch(apiUrl, {

View File

@@ -7,8 +7,22 @@ export default defineConfig(({ mode }) => {
// 加载环境变量
const env = loadEnv(mode, process.cwd(), '')
// 自定义重定向插件
const redirectPlugin = () => {
return {
name: 'redirect-plugin',
configureServer(server) {
server.middlewares.use('/login', (req, res, next) => {
res.writeHead(302, { Location: '/farm/login' })
res.end()
})
}
}
}
return {
plugins: [vue()],
base: '/farm/',
plugins: [vue(), redirectPlugin()],
resolve: {
alias: {
'@': resolve(__dirname, 'src')
@@ -23,6 +37,11 @@ export default defineConfig(({ mode }) => {
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/api')
}
},
// 开发环境重定向配置
middlewareMode: false,
fs: {
strict: false
}
},
build: {
@@ -38,7 +57,11 @@ export default defineConfig(({ mode }) => {
},
define: {
// 将环境变量注入到应用中
__APP_ENV__: JSON.stringify(env)
__APP_ENV__: JSON.stringify(env),
// 在生产环境中强制使用正确的API URL
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(
mode === 'production' ? 'https://ad.ningmuyun.com/farm/api' : (env.VITE_API_BASE_URL || '/api')
)
}
}
})