feat: Add build scripts and runtime config support

Backend:
- Add setup-backend.sh/bat for one-click backend setup
- Fix test_auth.py mock settings (JWT_EXPIRE_HOURS)
- Fix test_excel_export.py TEMPLATE_DIR reference

Frontend:
- Add config.json for runtime API URL configuration
- Add init.js and settings.js for config loading
- Update main.js to load config from external file
- Update api.js to use dynamic API_BASE_URL
- Update all pages to initialize config before API calls
- Update package.json with extraResources for config

Build:
- Add build-client.sh/bat for packaging Electron + Sidecar
- Add build-all.ps1 PowerShell script with -ApiUrl parameter
- Add GitHub Actions workflow for Windows builds
- Add scripts/README.md documentation

This allows IT to configure backend URL without rebuilding.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
egg
2025-12-16 20:03:16 +08:00
parent 01aee1fd0d
commit 7d4fc69071
20 changed files with 2454 additions and 32 deletions

View File

@@ -1,5 +1,34 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || "http://localhost:8000/api";
const UPLOAD_TIMEOUT = parseInt(import.meta.env.VITE_UPLOAD_TIMEOUT || "600000", 10);
/**
* API Service Module
*
* API base URL and settings are loaded from external config at runtime,
* allowing deployment configuration without rebuilding.
*/
// Settings will be loaded from config.json via Electron IPC
let API_BASE_URL = "http://localhost:8000/api";
let UPLOAD_TIMEOUT = 600000;
let _settingsLoaded = false;
/**
* Initialize API settings from external config
* Called by Electron preload or at app startup
*/
export async function initializeApi(settings) {
if (settings) {
API_BASE_URL = settings.apiBaseUrl || API_BASE_URL;
UPLOAD_TIMEOUT = settings.uploadTimeout || UPLOAD_TIMEOUT;
_settingsLoaded = true;
console.log("API initialized with:", { API_BASE_URL, UPLOAD_TIMEOUT });
}
}
/**
* Get current API base URL
*/
export function getApiBaseUrl() {
return API_BASE_URL;
}
let authToken = null;
let tokenRefreshTimer = null;

View File

@@ -0,0 +1,39 @@
/**
* App Initialization Module
*
* Loads configuration from Electron main process and initializes API settings.
* Should be imported and called at the start of every page.
*/
import { initializeApi } from './api.js';
let _initialized = false;
/**
* Initialize the app with configuration from main process
* Call this at the start of every page
*/
export async function initApp() {
if (_initialized) return;
try {
// Get config from Electron main process
if (window.electronAPI?.getConfig) {
const config = await window.electronAPI.getConfig();
await initializeApi(config);
console.log("App initialized with config:", config);
} else {
console.warn("electronAPI not available, using defaults");
}
_initialized = true;
} catch (error) {
console.error("Failed to initialize app:", error);
}
}
/**
* Check if app is initialized
*/
export function isInitialized() {
return _initialized;
}