服务打包初步结构

This commit is contained in:
2026-01-02 14:56:14 +08:00
parent 19026c1b30
commit 89bc8bf1d4
77 changed files with 5290 additions and 2070 deletions

View File

@@ -1,28 +1,12 @@
/**
* @description 应用运行时配置
* @author yslg
* @since 2025-12-06
*
* 配置加载策略:
* 1. 开发环境:使用下面定义的开发配置
* 1. 开发环境:使用内置开发配置
* 2. 生产环境:从 window.APP_RUNTIME_CONFIG 读取(来自 app-config.js
* 3. Docker部署替换 app-config.js 文件实现配置外挂
*
* 配置结构说明:
* 此文件的配置结构与 app-config.js 完全对应
* 修改 app-config.js 后,这里的配置会自动应用
* 3. Docker部署启动时替换 app-config.js 中的占位符
*/
// ============================================
// AES 加密密钥
// ============================================
/**
* AES 加密密钥(与后端保持一致)
* 对应后端配置security.aes.secret-key
* Base64 编码的 32 字节密钥256 位)
*/
export const AES_SECRET_KEY = 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=' // Base64 编码,解码后是 "12345678901234567890123456789012" (32字节)
export const AGENT_ID = '17664699513920001'
// ============================================
// 类型定义
// ============================================
@@ -53,11 +37,14 @@ export interface AppRuntimeConfig {
};
publicImgPath: string;
publicWebPath: string;
// 单点登录配置
sso?: {
platformUrl: string; // platform 平台地址
workcaseUrl: string; // workcase 服务地址
biddingUrl: string; // bidding 服务地址
platformUrl: string;
workcaseUrl: string;
biddingUrl: string;
};
aesSecretKey?: string;
jitsi?: {
serverUrl: string;
};
features?: {
enableDebug?: boolean;
@@ -67,103 +54,86 @@ export interface AppRuntimeConfig {
}
// ============================================
// 配置定义(与 app-config.js 结构一致)
// 环境检测
// ============================================
const isDev = (import.meta as any).env?.DEV ?? false;
// ============================================
// 开发环境配置
// ============================================
const devConfig: AppRuntimeConfig = {
env: 'development',
api: {
// 开发环境通过 Vite 代理转发到后端,避免浏览器直接跨域
// 实际请求路径示例:/api/... → 由代理转发到实际后端
baseUrl: '/api',
timeout: 30000
},
baseUrl: '/',
file: {
// 通过 Nginx → Gateway 访问文件服务,使用 /urban-lifeline 前缀
downloadUrl: '/api/urban-lifeline/file/download/',
uploadUrl: '/api/urban-lifeline/file/upload',
maxSize: {
image: 5,
video: 100,
document: 10
},
maxSize: { image: 5, video: 100, document: 10 },
acceptTypes: {
image: 'image/*',
video: 'video/*',
document: '.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx'
}
},
token: {
key: 'token',
refreshThreshold: 300000
},
publicImgPath: 'http://localhost:5173/img',
publicWebPath: 'http://localhost:5173',
// 单点登录配置
// 推荐开发环境也通过nginx访问http://localhost
// 备选直接访问各服务端口platformUrl: 'http://localhost:7001'
publicImgPath: '/img',
publicWebPath: '/',
sso: {
platformUrl: '/', // 通过nginx访问platform
workcaseUrl: '/workcase', // 通过nginx访问workcase
biddingUrl: '/bidding' // 通过nginx访问bidding
platformUrl: '/',
workcaseUrl: '/workcase',
biddingUrl: '/bidding'
},
aesSecretKey: 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=',
jitsi: {
serverUrl: 'https://meet.example.com'
},
features: {
enableDebug: true,
enableMockData: false
}
};
// ============================================
// 生产环境默认配置(兜底)
// ============================================
const prodDefaultConfig: AppRuntimeConfig = {
env: 'production',
api: {
baseUrl: '/api',
timeout: 30000
},
baseUrl: '/',
file: {
downloadUrl: '/api/file/download/',
uploadUrl: '/api/file/upload',
maxSize: {
image: 5,
video: 100,
document: 10
},
downloadUrl: '/api/urban-lifeline/file/download/',
uploadUrl: '/api/urban-lifeline/file/upload',
maxSize: { image: 5, video: 100, document: 10 },
acceptTypes: {
image: 'image/*',
video: 'video/*',
document: '.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx'
}
},
token: {
key: 'token',
refreshThreshold: 300000
},
publicImgPath: '/img',
publicWebPath: '/',
// 单点登录配置生产环境通过nginx代理
sso: {
platformUrl: '/',
workcaseUrl: '/workcase',
biddingUrl: '/bidding'
},
aesSecretKey: 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=',
jitsi: {
serverUrl: 'https://meet.example.com'
},
features: {
enableDebug: false,
enableMockData: false
@@ -174,96 +144,90 @@ const prodDefaultConfig: AppRuntimeConfig = {
// 配置加载
// ============================================
/**
* 检查值是否为未替换的占位符
*/
const isPlaceholder = (value: any): boolean => {
return typeof value === 'string' && value.startsWith('__') && value.endsWith('__');
};
/**
* 深度合并配置,跳过占位符值
*/
const mergeConfig = (target: any, source: any): any => {
const result = { ...target };
for (const key in source) {
const value = source[key];
if (value && typeof value === 'object' && !Array.isArray(value)) {
result[key] = mergeConfig(target[key] || {}, value);
} else if (!isPlaceholder(value)) {
result[key] = value;
}
}
return result;
};
/**
* 获取运行时配置
* 生产环境优先从 window.APP_RUNTIME_CONFIG 读取app-config.js 注入)
*/
const getRuntimeConfig = (): AppRuntimeConfig => {
if (isDev) {
console.log('[配置] 开发环境,使用内置配置');
console.log('[Config] 开发环境,使用内置配置');
return devConfig;
}
// 生产环境:尝试读取外部配置
try {
const runtimeConfig = (window as any).APP_RUNTIME_CONFIG;
if (runtimeConfig && typeof runtimeConfig === 'object') {
console.log('[配置] 加载外部配置 app-config.js');
console.log('[配置] API地址:', runtimeConfig.api?.baseUrl);
console.log('[配置] 环境:', runtimeConfig.env || 'production');
return runtimeConfig as AppRuntimeConfig;
const merged = mergeConfig(prodDefaultConfig, runtimeConfig);
console.log('[Config] 加载运行时配置', merged);
return merged;
}
} catch (e) {
console.warn('[配置] 无法读取外部配置,使用默认配置', e);
console.warn('[Config] 无法读取外部配置', e);
}
console.log('[配置] 使用默认生产配置');
console.log('[Config] 使用默认生产配置');
return prodDefaultConfig;
};
// 当前应用配置
// 当前配置
const config = getRuntimeConfig();
console.log('[配置] 当前配置', config);
// ============================================
// 导出配置(向后兼容)
// 导出
// ============================================
// 单独导出常用配置项
// AES 密钥
export const AES_SECRET_KEY = config.aesSecretKey || 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=';
// AI Agent ID
export const AGENT_ID = '17664699513920001';
// 常用配置项
export const API_BASE_URL = config.api.baseUrl;
export const FILE_DOWNLOAD_URL = config.file.downloadUrl;
export const FILE_UPLOAD_URL = config.file.uploadUrl;
export const PUBLIC_IMG_PATH = config.publicImgPath;
export const PUBLIC_WEB_PATH = config.publicWebPath;
// 文件上传大小限制100MB
export const FILE_MAX_SIZE = 100 * 1024 * 1024;
// 导出完整配置对象
// Jitsi 配置
export const JITSI_SERVER_URL = config.jitsi?.serverUrl || 'https://meet.example.com';
// 完整配置对象
export const APP_CONFIG = {
// 应用标题
title: '泰豪电源 AI 数智化平台',
// 环境标识
title: '泰豪电源工单系统',
env: config.env || 'production',
// 应用基础路径
baseUrl: config.baseUrl,
// API 配置
api: {
baseUrl: config.api.baseUrl,
timeout: config.api.timeout
},
// 文件配置
file: {
downloadUrl: config.file.downloadUrl,
uploadUrl: config.file.uploadUrl,
maxSize: config.file.maxSize,
acceptTypes: config.file.acceptTypes
},
// Token 配置
token: {
key: config.token.key,
refreshThreshold: config.token.refreshThreshold
},
// 公共路径
api: config.api,
file: config.file,
token: config.token,
publicImgPath: config.publicImgPath,
publicWebPath: config.publicWebPath,
// 单点登录配置
sso: config.sso || {
platformUrl: '/',
workcaseUrl: '/workcase',
biddingUrl: '/bidding'
},
// 功能开关
sso: config.sso || { platformUrl: '/', workcaseUrl: '/workcase', biddingUrl: '/bidding' },
jitsi: config.jitsi || { serverUrl: 'https://meet.example.com' },
features: config.features || {}
};
// 默认导出
export default APP_CONFIG;