diff --git a/ELECTRON.md b/ELECTRON.md index 1087c1e..5822a21 100644 --- a/ELECTRON.md +++ b/ELECTRON.md @@ -14,6 +14,14 @@ pnpm electron:dev pnpm electron:build ``` +也可以直接双击项目根目录的 `build-electron.cmd`。它会自动检查 Node.js/pnpm,在依赖缺失时执行安装,随后构建 Electron 安装包并在成功后打开输出目录。 + +对应的命令行入口为: + +```bash +pnpm electron:package:auto +``` + 安装包输出到 `release/`。只生成免安装目录用于调试时,可运行: ```bash diff --git a/build-electron.cmd b/build-electron.cmd new file mode 100644 index 0000000..2028a08 --- /dev/null +++ b/build-electron.cmd @@ -0,0 +1,21 @@ +@echo off +chcp 65001 >nul +title 跃动赛事 Electron 自动打包 +cd /d "%~dp0" + +echo ======================================== +echo 跃动赛事 Electron 自动打包 +echo ======================================== +echo. + +powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\package-electron.ps1" +if errorlevel 1 ( + echo. + echo 打包失败,请查看上方错误信息。 + pause + exit /b 1 +) + +echo. +echo 打包任务已完成。 +pause diff --git a/package.json b/package.json index b57eb6b..1d49e63 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "electron:dev": "concurrently -k \"vite --mode electron\" \"wait-on http://127.0.0.1:9991 && electron .\"", "electron:build": "vite build --mode electron --outDir dist && electron-builder", "electron:build:dir": "vite build --mode electron --outDir dist && electron-builder --dir", + "electron:package:auto": "powershell -NoProfile -ExecutionPolicy Bypass -File scripts/package-electron.ps1", "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/", "gen": "sta -p http://localhost:53785/swagger/Default/swagger.json -o ./src/apis --modular --route-types --axios --module-name-index 1 --extract-request-params -t ./templates" }, diff --git a/scripts/package-electron.ps1 b/scripts/package-electron.ps1 new file mode 100644 index 0000000..95e42bb --- /dev/null +++ b/scripts/package-electron.ps1 @@ -0,0 +1,73 @@ +param( + [switch]$NoOpen +) + +$ErrorActionPreference = 'Stop' + +$workspaceRoot = Split-Path -Parent $PSScriptRoot +$releaseDirectory = Join-Path $workspaceRoot 'release' +$electronBuilderCommand = Join-Path $workspaceRoot 'node_modules\.bin\electron-builder.CMD' + +Set-Location -LiteralPath $workspaceRoot + +function Invoke-CheckedCommand { + param( + [Parameter(Mandatory = $true)] + [string]$Command, + [string[]]$Arguments = @() + ) + + & $Command @Arguments + if ($LASTEXITCODE -ne 0) { + throw "Command failed with exit code ${LASTEXITCODE}: $Command $($Arguments -join ' ')" + } +} + +try { + Write-Host '[1/4] Checking Node.js and pnpm...' -ForegroundColor Cyan + if (-not (Get-Command node -ErrorAction SilentlyContinue)) { + throw 'Node.js was not found. Install Node.js 20 first.' + } + if (-not (Get-Command pnpm -ErrorAction SilentlyContinue)) { + throw 'pnpm was not found. Run: corepack enable' + } + + $nodeVersion = (& node --version).Trim() + $pnpmVersion = (& pnpm --version).Trim() + Write-Host "Node.js $nodeVersion, pnpm $pnpmVersion" -ForegroundColor DarkGray + + Write-Host '[2/4] Checking project dependencies...' -ForegroundColor Cyan + if (-not (Test-Path -LiteralPath $electronBuilderCommand)) { + Write-Host 'Dependencies are missing. Running pnpm install...' + Invoke-CheckedCommand -Command 'pnpm' -Arguments @('install') + } else { + Write-Host 'Dependencies found. Skipping installation.' -ForegroundColor DarkGray + } + + Write-Host '[3/4] Building the Electron installer...' -ForegroundColor Cyan + $env:ELECTRON_MIRROR = 'https://npmmirror.com/mirrors/electron/' + Invoke-CheckedCommand -Command 'pnpm' -Arguments @('electron:build') + + Write-Host '[4/4] Checking build output...' -ForegroundColor Cyan + $installer = Get-ChildItem -LiteralPath $releaseDirectory -Filter '*.exe' -File | + Sort-Object LastWriteTime -Descending | + Select-Object -First 1 + + if (-not $installer) { + throw "The build completed, but no installer was found in $releaseDirectory." + } + + $sizeMb = [Math]::Round($installer.Length / 1MB, 2) + Write-Host '' + Write-Host 'Build completed successfully.' -ForegroundColor Green + Write-Host "Installer: $($installer.FullName)" + Write-Host "Size: $sizeMb MB" + + if (-not $NoOpen) { + Start-Process -FilePath 'explorer.exe' -ArgumentList "/select,`"$($installer.FullName)`"" + } +} catch { + Write-Host '' + Write-Host "Automatic packaging failed: $($_.Exception.Message)" -ForegroundColor Red + exit 1 +} diff --git a/src/views/scoring/workbench/index.vue b/src/views/scoring/workbench/index.vue index 43dca5e..31f602b 100644 --- a/src/views/scoring/workbench/index.vue +++ b/src/views/scoring/workbench/index.vue @@ -3,7 +3,7 @@

{{ tabTitle }}

{{ eventName }} · {{ tabDescription }}

-
● {{ offline ? '连接异常' : '实时同步' }}检录大屏{{activeTab==='corrections'?'返回成绩列表':'修正申请'}}切换赛事
+
● {{ offline ? '连接异常' : '实时同步' }}检录大屏切换赛事