添加Windows支持脚本
- start-industry.bat: Windows批处理脚本 - start-industry.ps1: PowerShell脚本(功能更强大) 现在支持跨平台使用: - Linux/Mac: ./start-industry.sh - Windows CMD: start-industry.bat - Windows PowerShell: .\start-industry.ps1
This commit is contained in:
255
start-industry.bat
Normal file
255
start-industry.bat
Normal file
@@ -0,0 +1,255 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: ========================================
|
||||
:: 教务系统 - Windows智能启动脚本
|
||||
:: ========================================
|
||||
|
||||
:: 颜色定义
|
||||
color 0A
|
||||
|
||||
:: 清屏并显示标题
|
||||
:MAIN_MENU
|
||||
cls
|
||||
echo ========================================
|
||||
echo 教务系统 - 智能启动脚本 (Windows)
|
||||
echo ========================================
|
||||
echo.
|
||||
echo 请选择操作:
|
||||
echo.
|
||||
echo 0) 启动所有产业
|
||||
echo --------------
|
||||
echo 1) 文旅产业 (端口: 5150)
|
||||
echo 2) 智能制造 (端口: 5151)
|
||||
echo 3) 智能开发 (端口: 5152)
|
||||
echo 4) 财经商贸 (端口: 5153)
|
||||
echo 5) 视觉设计 (端口: 5154)
|
||||
echo 6) 交通物流 (端口: 5155)
|
||||
echo 7) 大健康 (端口: 5156)
|
||||
echo 8) 土木水利 (端口: 5157)
|
||||
echo 9) 食品产业 (端口: 5158)
|
||||
echo 10) 化工产业 (端口: 5159)
|
||||
echo 11) 能源产业 (端口: 5160)
|
||||
echo 12) 环保产业 (端口: 5161)
|
||||
echo --------------
|
||||
echo a) 停止所有产业
|
||||
echo s) 查看运行状态
|
||||
echo q) 退出
|
||||
echo.
|
||||
|
||||
set /p choice=请输入选项:
|
||||
|
||||
if "%choice%"=="0" goto START_ALL
|
||||
if "%choice%"=="1" goto START_1
|
||||
if "%choice%"=="2" goto START_2
|
||||
if "%choice%"=="3" goto START_3
|
||||
if "%choice%"=="4" goto START_4
|
||||
if "%choice%"=="5" goto START_5
|
||||
if "%choice%"=="6" goto START_6
|
||||
if "%choice%"=="7" goto START_7
|
||||
if "%choice%"=="8" goto START_8
|
||||
if "%choice%"=="9" goto START_9
|
||||
if "%choice%"=="10" goto START_10
|
||||
if "%choice%"=="11" goto START_11
|
||||
if "%choice%"=="12" goto START_12
|
||||
if /i "%choice%"=="a" goto STOP_ALL
|
||||
if /i "%choice%"=="s" goto CHECK_STATUS
|
||||
if /i "%choice%"=="q" goto EXIT
|
||||
|
||||
echo 无效选项!
|
||||
timeout /t 2 >nul
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_ALL
|
||||
echo.
|
||||
echo 正在启动所有产业...
|
||||
call :START_INDUSTRY frontend "文旅产业" 5150
|
||||
call :START_INDUSTRY frontend_智能制造 "智能制造" 5151
|
||||
call :START_INDUSTRY frontend_智能开发 "智能开发" 5152
|
||||
call :START_INDUSTRY frontend_财经商贸 "财经商贸" 5153
|
||||
call :START_INDUSTRY frontend_视觉设计 "视觉设计" 5154
|
||||
call :START_INDUSTRY frontend_交通物流 "交通物流" 5155
|
||||
call :START_INDUSTRY frontend_大健康 "大健康" 5156
|
||||
call :START_INDUSTRY frontend_土木水利 "土木水利" 5157
|
||||
call :START_INDUSTRY frontend_食品 "食品产业" 5158
|
||||
call :START_INDUSTRY frontend_化工 "化工产业" 5159
|
||||
call :START_INDUSTRY frontend_能源 "能源产业" 5160
|
||||
call :START_INDUSTRY frontend_环保 "环保产业" 5161
|
||||
echo.
|
||||
echo 所有产业启动完成!
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_1
|
||||
call :START_INDUSTRY frontend "文旅产业" 5150
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_2
|
||||
call :START_INDUSTRY frontend_智能制造 "智能制造" 5151
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_3
|
||||
call :START_INDUSTRY frontend_智能开发 "智能开发" 5152
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_4
|
||||
call :START_INDUSTRY frontend_财经商贸 "财经商贸" 5153
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_5
|
||||
call :START_INDUSTRY frontend_视觉设计 "视觉设计" 5154
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_6
|
||||
call :START_INDUSTRY frontend_交通物流 "交通物流" 5155
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_7
|
||||
call :START_INDUSTRY frontend_大健康 "大健康" 5156
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_8
|
||||
call :START_INDUSTRY frontend_土木水利 "土木水利" 5157
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_9
|
||||
call :START_INDUSTRY frontend_食品 "食品产业" 5158
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_10
|
||||
call :START_INDUSTRY frontend_化工 "化工产业" 5159
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_11
|
||||
call :START_INDUSTRY frontend_能源 "能源产业" 5160
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:START_12
|
||||
call :START_INDUSTRY frontend_环保 "环保产业" 5161
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:: 启动单个产业的函数
|
||||
:START_INDUSTRY
|
||||
set dir=%1
|
||||
set name=%2
|
||||
set port=%3
|
||||
|
||||
echo.
|
||||
echo ========================================
|
||||
echo 启动 %name% (端口: %port%)
|
||||
echo ========================================
|
||||
|
||||
:: 检查目录是否存在
|
||||
if not exist "%dir%" (
|
||||
echo [错误] 目录 %dir% 不存在!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: 检查端口是否被占用
|
||||
netstat -an | findstr ":%port%" >nul
|
||||
if %errorlevel%==0 (
|
||||
echo [警告] 端口 %port% 已被占用
|
||||
set /p stop_choice=是否停止现有服务并重启?(y/n):
|
||||
if /i "!stop_choice!"=="y" (
|
||||
echo 正在停止端口 %port% 的服务...
|
||||
for /f "tokens=5" %%a in ('netstat -aon ^| findstr ":%port%"') do (
|
||||
taskkill /F /PID %%a >nul 2>&1
|
||||
)
|
||||
timeout /t 2 >nul
|
||||
) else (
|
||||
echo 跳过 %name%
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
:: 检查并安装依赖
|
||||
cd %dir%
|
||||
if not exist "node_modules" (
|
||||
echo [信息] 检测到依赖未安装,正在安装...
|
||||
echo 这可能需要1-3分钟,请稍候...
|
||||
call npm install
|
||||
if !errorlevel! neq 0 (
|
||||
echo [错误] %name% 依赖安装失败!
|
||||
cd ..
|
||||
exit /b 1
|
||||
)
|
||||
echo [成功] %name% 依赖安装成功!
|
||||
) else (
|
||||
echo [信息] %name% 依赖已存在
|
||||
)
|
||||
|
||||
:: 启动服务
|
||||
echo [信息] 正在启动 %name%...
|
||||
start /min cmd /c "npm run dev"
|
||||
cd ..
|
||||
|
||||
timeout /t 3 >nul
|
||||
|
||||
:: 验证启动
|
||||
netstat -an | findstr ":%port%" >nul
|
||||
if %errorlevel%==0 (
|
||||
echo [成功] %name% 启动成功!
|
||||
echo 访问地址: http://localhost:%port%
|
||||
) else (
|
||||
echo [错误] %name% 启动失败!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
exit /b 0
|
||||
|
||||
:STOP_ALL
|
||||
echo.
|
||||
echo 正在停止所有产业服务...
|
||||
:: 停止所有node进程
|
||||
taskkill /F /IM node.exe >nul 2>&1
|
||||
echo 所有服务已停止
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:CHECK_STATUS
|
||||
cls
|
||||
echo ========================================
|
||||
echo 产业运行状态检查
|
||||
echo ========================================
|
||||
echo.
|
||||
call :CHECK_PORT 5150 "文旅产业"
|
||||
call :CHECK_PORT 5151 "智能制造"
|
||||
call :CHECK_PORT 5152 "智能开发"
|
||||
call :CHECK_PORT 5153 "财经商贸"
|
||||
call :CHECK_PORT 5154 "视觉设计"
|
||||
call :CHECK_PORT 5155 "交通物流"
|
||||
call :CHECK_PORT 5156 "大健康"
|
||||
call :CHECK_PORT 5157 "土木水利"
|
||||
call :CHECK_PORT 5158 "食品产业"
|
||||
call :CHECK_PORT 5159 "化工产业"
|
||||
call :CHECK_PORT 5160 "能源产业"
|
||||
call :CHECK_PORT 5161 "环保产业"
|
||||
echo.
|
||||
pause
|
||||
goto MAIN_MENU
|
||||
|
||||
:CHECK_PORT
|
||||
netstat -an | findstr ":%1" >nul
|
||||
if %errorlevel%==0 (
|
||||
echo [运行中] %2 (端口: %1) - http://localhost:%1
|
||||
) else (
|
||||
echo [未启动] %2 (端口: %1)
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:EXIT
|
||||
echo 再见!
|
||||
exit
|
||||
257
start-industry.ps1
Normal file
257
start-industry.ps1
Normal file
@@ -0,0 +1,257 @@
|
||||
# 教务系统 - PowerShell智能启动脚本
|
||||
# 使用方法: PowerShell中运行 .\start-industry.ps1
|
||||
|
||||
# 设置执行策略(如果需要)
|
||||
# Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
|
||||
# 产业配置
|
||||
$industries = @(
|
||||
@{Number=1; Dir="frontend"; Name="文旅产业"; Port=5150},
|
||||
@{Number=2; Dir="frontend_智能制造"; Name="智能制造"; Port=5151},
|
||||
@{Number=3; Dir="frontend_智能开发"; Name="智能开发"; Port=5152},
|
||||
@{Number=4; Dir="frontend_财经商贸"; Name="财经商贸"; Port=5153},
|
||||
@{Number=5; Dir="frontend_视觉设计"; Name="视觉设计"; Port=5154},
|
||||
@{Number=6; Dir="frontend_交通物流"; Name="交通物流"; Port=5155},
|
||||
@{Number=7; Dir="frontend_大健康"; Name="大健康"; Port=5156},
|
||||
@{Number=8; Dir="frontend_土木水利"; Name="土木水利"; Port=5157},
|
||||
@{Number=9; Dir="frontend_食品"; Name="食品产业"; Port=5158},
|
||||
@{Number=10; Dir="frontend_化工"; Name="化工产业"; Port=5159},
|
||||
@{Number=11; Dir="frontend_能源"; Name="能源产业"; Port=5160},
|
||||
@{Number=12; Dir="frontend_环保"; Name="环保产业"; Port=5161}
|
||||
)
|
||||
|
||||
# 颜色输出函数
|
||||
function Write-ColorOutput {
|
||||
param(
|
||||
[string]$Message,
|
||||
[string]$Color = "White"
|
||||
)
|
||||
Write-Host $Message -ForegroundColor $Color
|
||||
}
|
||||
|
||||
# 检查端口是否被占用
|
||||
function Test-Port {
|
||||
param([int]$Port)
|
||||
$connection = Get-NetTCPConnection -LocalPort $Port -ErrorAction SilentlyContinue
|
||||
return $null -ne $connection
|
||||
}
|
||||
|
||||
# 停止占用端口的进程
|
||||
function Stop-PortProcess {
|
||||
param([int]$Port)
|
||||
$connection = Get-NetTCPConnection -LocalPort $Port -ErrorAction SilentlyContinue
|
||||
if ($connection) {
|
||||
$processId = $connection.OwningProcess
|
||||
Stop-Process -Id $processId -Force -ErrorAction SilentlyContinue
|
||||
Write-ColorOutput "已停止端口 $Port 的进程" "Yellow"
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
}
|
||||
|
||||
# 启动单个产业
|
||||
function Start-Industry {
|
||||
param(
|
||||
[hashtable]$Industry
|
||||
)
|
||||
|
||||
Write-Host ""
|
||||
Write-ColorOutput ("=" * 50) "Cyan"
|
||||
Write-ColorOutput "启动 $($Industry.Name) (端口: $($Industry.Port))" "Cyan"
|
||||
Write-ColorOutput ("=" * 50) "Cyan"
|
||||
|
||||
# 检查目录
|
||||
if (-not (Test-Path $Industry.Dir)) {
|
||||
Write-ColorOutput "[错误] 目录 $($Industry.Dir) 不存在!" "Red"
|
||||
return $false
|
||||
}
|
||||
|
||||
# 检查端口
|
||||
if (Test-Port -Port $Industry.Port) {
|
||||
Write-ColorOutput "[警告] 端口 $($Industry.Port) 已被占用" "Yellow"
|
||||
$choice = Read-Host "是否停止现有服务并重启?(y/n)"
|
||||
if ($choice -eq 'y' -or $choice -eq 'Y') {
|
||||
Stop-PortProcess -Port $Industry.Port
|
||||
} else {
|
||||
Write-ColorOutput "跳过 $($Industry.Name)" "Yellow"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
# 进入目录
|
||||
Push-Location $Industry.Dir
|
||||
|
||||
try {
|
||||
# 检查并安装依赖
|
||||
if (-not (Test-Path "node_modules")) {
|
||||
Write-ColorOutput "[信息] 检测到依赖未安装,正在安装..." "Yellow"
|
||||
Write-ColorOutput " 这可能需要1-3分钟,请稍候..." "Gray"
|
||||
|
||||
$process = Start-Process npm -ArgumentList "install" -PassThru -NoNewWindow -Wait
|
||||
|
||||
if ($process.ExitCode -eq 0) {
|
||||
Write-ColorOutput "[成功] $($Industry.Name) 依赖安装成功!" "Green"
|
||||
} else {
|
||||
Write-ColorOutput "[错误] $($Industry.Name) 依赖安装失败!" "Red"
|
||||
Pop-Location
|
||||
return $false
|
||||
}
|
||||
} else {
|
||||
Write-ColorOutput "[信息] $($Industry.Name) 依赖已存在" "Green"
|
||||
}
|
||||
|
||||
# 启动服务
|
||||
Write-ColorOutput "[信息] 正在启动 $($Industry.Name)..." "Cyan"
|
||||
Start-Process powershell -ArgumentList "-Command", "npm run dev" -WindowStyle Minimized
|
||||
|
||||
# 等待服务启动
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
# 验证启动
|
||||
if (Test-Port -Port $Industry.Port) {
|
||||
Write-ColorOutput "[成功] $($Industry.Name) 启动成功!" "Green"
|
||||
Write-ColorOutput " 访问地址: http://localhost:$($Industry.Port)" "White"
|
||||
return $true
|
||||
} else {
|
||||
Write-ColorOutput "[错误] $($Industry.Name) 启动失败!" "Red"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
# 启动所有产业
|
||||
function Start-AllIndustries {
|
||||
Write-ColorOutput "`n启动所有产业..." "Cyan"
|
||||
|
||||
$successCount = 0
|
||||
$failCount = 0
|
||||
|
||||
foreach ($industry in $industries) {
|
||||
if (Start-Industry -Industry $industry) {
|
||||
$successCount++
|
||||
} else {
|
||||
$failCount++
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-ColorOutput ("=" * 50) "Cyan"
|
||||
Write-ColorOutput "成功启动: $successCount 个产业" "Green"
|
||||
if ($failCount -gt 0) {
|
||||
Write-ColorOutput "启动失败: $failCount 个产业" "Red"
|
||||
}
|
||||
}
|
||||
|
||||
# 停止所有产业
|
||||
function Stop-AllIndustries {
|
||||
Write-ColorOutput "`n停止所有产业服务..." "Yellow"
|
||||
|
||||
# 停止所有node进程
|
||||
Get-Process node -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Write-ColorOutput "所有服务已停止" "Green"
|
||||
}
|
||||
|
||||
# 查看运行状态
|
||||
function Show-Status {
|
||||
Clear-Host
|
||||
Write-ColorOutput ("=" * 50) "Cyan"
|
||||
Write-ColorOutput " 产业运行状态检查" "Cyan"
|
||||
Write-ColorOutput ("=" * 50) "Cyan"
|
||||
Write-Host ""
|
||||
|
||||
foreach ($industry in $industries) {
|
||||
if (Test-Port -Port $industry.Port) {
|
||||
Write-ColorOutput "[运行中] $($industry.Name.PadRight(10)) (端口: $($industry.Port)) - http://localhost:$($industry.Port)" "Green"
|
||||
} else {
|
||||
Write-ColorOutput "[未启动] $($industry.Name.PadRight(10)) (端口: $($industry.Port))" "Red"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 显示菜单
|
||||
function Show-Menu {
|
||||
Clear-Host
|
||||
Write-ColorOutput ("=" * 50) "Cyan"
|
||||
Write-ColorOutput " 教务系统 - 智能启动脚本 (PowerShell)" "Cyan"
|
||||
Write-ColorOutput ("=" * 50) "Cyan"
|
||||
Write-Host ""
|
||||
Write-ColorOutput "请选择操作:" "White"
|
||||
Write-Host ""
|
||||
Write-ColorOutput " 0) 启动所有产业" "White"
|
||||
Write-ColorOutput " --------------" "Gray"
|
||||
|
||||
foreach ($industry in $industries) {
|
||||
$status = if (Test-Port -Port $industry.Port) { "[运行中]" } else { "[未启动]" }
|
||||
$color = if (Test-Port -Port $industry.Port) { "Green" } else { "Yellow" }
|
||||
Write-Host (" {0,2}) {1,-10} (端口: {2}) " -f $industry.Number, $industry.Name, $industry.Port) -NoNewline
|
||||
Write-Host $status -ForegroundColor $color
|
||||
}
|
||||
|
||||
Write-ColorOutput " --------------" "Gray"
|
||||
Write-ColorOutput " a) 停止所有产业" "White"
|
||||
Write-ColorOutput " s) 查看运行状态" "White"
|
||||
Write-ColorOutput " q) 退出" "White"
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
# 主循环
|
||||
function Main {
|
||||
# 检查是否有命令行参数
|
||||
if ($args.Count -gt 0) {
|
||||
switch ($args[0]) {
|
||||
"all" { Start-AllIndustries }
|
||||
"stop" { Stop-AllIndustries }
|
||||
"status" { Show-Status }
|
||||
default {
|
||||
if ([int]::TryParse($args[0], [ref]$null)) {
|
||||
$num = [int]$args[0]
|
||||
if ($num -ge 1 -and $num -le $industries.Count) {
|
||||
Start-Industry -Industry $industries[$num - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
# 交互模式
|
||||
while ($true) {
|
||||
Show-Menu
|
||||
|
||||
$choice = Read-Host "请输入选项"
|
||||
|
||||
switch ($choice) {
|
||||
"0" {
|
||||
Start-AllIndustries
|
||||
Read-Host "`n按回车键继续..."
|
||||
}
|
||||
{$_ -match "^[1-9]$|^1[0-2]$"} {
|
||||
$num = [int]$choice
|
||||
Start-Industry -Industry $industries[$num - 1]
|
||||
Read-Host "`n按回车键继续..."
|
||||
}
|
||||
{$_ -eq "a" -or $_ -eq "A"} {
|
||||
Stop-AllIndustries
|
||||
Read-Host "`n按回车键继续..."
|
||||
}
|
||||
{$_ -eq "s" -or $_ -eq "S"} {
|
||||
Show-Status
|
||||
Read-Host "`n按回车键继续..."
|
||||
}
|
||||
{$_ -eq "q" -or $_ -eq "Q"} {
|
||||
Write-ColorOutput "再见!" "Cyan"
|
||||
return
|
||||
}
|
||||
default {
|
||||
Write-ColorOutput "无效选项!" "Red"
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 启动主程序
|
||||
Main
|
||||
Reference in New Issue
Block a user