镜像制作
This commit is contained in:
@@ -2,41 +2,77 @@
|
||||
* @description 应用配置
|
||||
* @author yslg
|
||||
* @since 2025-10-18
|
||||
*
|
||||
* 配置加载策略:
|
||||
* 1. 开发环境:使用下面定义的开发配置
|
||||
* 2. 生产环境:从 window.APP_RUNTIME_CONFIG 读取(来自 app-config.js)
|
||||
* 3. Docker部署:替换 app-config.js 文件实现配置外挂
|
||||
*
|
||||
* 配置结构说明:
|
||||
* 此文件的配置结构与 app-config.js 完全对应
|
||||
* 修改 app-config.js 后,这里的配置会自动应用
|
||||
*/
|
||||
|
||||
// 开发环境和生产环境的配置
|
||||
// ============================================
|
||||
// 类型定义
|
||||
// ============================================
|
||||
export interface AppRuntimeConfig {
|
||||
env?: string;
|
||||
api: {
|
||||
baseUrl: string;
|
||||
timeout: number;
|
||||
};
|
||||
baseUrl: string;
|
||||
file: {
|
||||
downloadUrl: string;
|
||||
uploadUrl: string;
|
||||
maxSize: {
|
||||
image: number;
|
||||
video: number;
|
||||
document: number;
|
||||
};
|
||||
acceptTypes: {
|
||||
image: string;
|
||||
video: string;
|
||||
document: string;
|
||||
};
|
||||
};
|
||||
token: {
|
||||
key: string;
|
||||
refreshThreshold: number;
|
||||
};
|
||||
publicImgPath: string;
|
||||
publicWebPath: string;
|
||||
features?: {
|
||||
enableDebug?: boolean;
|
||||
enableMockData?: boolean;
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 配置定义(与 app-config.js 结构一致)
|
||||
// ============================================
|
||||
const isDev = import.meta.env.DEV;
|
||||
|
||||
// API 基础路径
|
||||
export const API_BASE_URL = isDev
|
||||
? 'http://127.0.0.1:8081/schoolNewsServ'
|
||||
: '/schoolNewsServ';
|
||||
|
||||
// 文件下载路径
|
||||
export const FILE_DOWNLOAD_URL = `${API_BASE_URL}/file/download/`;
|
||||
|
||||
// 应用配置
|
||||
export const APP_CONFIG = {
|
||||
// 应用标题
|
||||
title: '校园新闻管理系统',
|
||||
// 开发环境配置
|
||||
const devConfig: AppRuntimeConfig = {
|
||||
env: 'development',
|
||||
|
||||
// 基础路径
|
||||
baseUrl: '/schoolNewsWeb/',
|
||||
|
||||
// API 配置
|
||||
api: {
|
||||
baseUrl: API_BASE_URL,
|
||||
baseUrl: 'http://127.0.0.1:8081/schoolNewsServ',
|
||||
timeout: 30000
|
||||
},
|
||||
|
||||
// 文件配置
|
||||
baseUrl: '/schoolNewsWeb/',
|
||||
|
||||
file: {
|
||||
downloadUrl: FILE_DOWNLOAD_URL,
|
||||
uploadUrl: `${API_BASE_URL}/file/upload`,
|
||||
downloadUrl: 'http://127.0.0.1:8081/schoolNewsServ/file/download/',
|
||||
uploadUrl: 'http://127.0.0.1:8081/schoolNewsServ/file/upload',
|
||||
maxSize: {
|
||||
image: 5, // MB
|
||||
video: 100, // MB
|
||||
document: 10 // MB
|
||||
image: 5,
|
||||
video: 100,
|
||||
document: 10
|
||||
},
|
||||
acceptTypes: {
|
||||
image: 'image/*',
|
||||
@@ -45,13 +81,142 @@ export const APP_CONFIG = {
|
||||
}
|
||||
},
|
||||
|
||||
// Token 配置
|
||||
token: {
|
||||
key: 'token',
|
||||
refreshThreshold: 5 * 60 * 1000 // 提前5分钟刷新
|
||||
refreshThreshold: 300000
|
||||
},
|
||||
|
||||
publicImgPath: 'http://localhost:8080/schoolNewsWeb/img',
|
||||
publicWebPath: 'http://localhost:8080/schoolNewsWeb',
|
||||
|
||||
features: {
|
||||
enableDebug: true,
|
||||
enableMockData: false
|
||||
}
|
||||
};
|
||||
export const PUBLIC_IMG_PATH = 'http://localhost:8080/schoolNewsWeb/img';
|
||||
export const PUBLIC_WEB_PATH = 'http://localhost:8080/schoolNewsWeb';
|
||||
export default APP_CONFIG;
|
||||
|
||||
// 生产环境默认配置(兜底)
|
||||
const prodDefaultConfig: AppRuntimeConfig = {
|
||||
env: 'production',
|
||||
|
||||
api: {
|
||||
baseUrl: '/schoolNewsServ',
|
||||
timeout: 30000
|
||||
},
|
||||
|
||||
baseUrl: '/schoolNewsWeb/',
|
||||
|
||||
file: {
|
||||
downloadUrl: '/schoolNewsServ/file/download/',
|
||||
uploadUrl: '/schoolNewsServ/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: '/schoolNewsWeb/img',
|
||||
publicWebPath: '/schoolNewsWeb',
|
||||
|
||||
features: {
|
||||
enableDebug: false,
|
||||
enableMockData: false
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================
|
||||
// 配置加载
|
||||
// ============================================
|
||||
|
||||
/**
|
||||
* 获取运行时配置
|
||||
* 生产环境优先从 window.APP_RUNTIME_CONFIG 读取(app-config.js 注入)
|
||||
*/
|
||||
const getRuntimeConfig = (): AppRuntimeConfig => {
|
||||
if (isDev) {
|
||||
console.log('[配置] 开发环境,使用内置配置');
|
||||
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;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[配置] 无法读取外部配置,使用默认配置', e);
|
||||
}
|
||||
|
||||
console.log('[配置] 使用默认生产配置');
|
||||
return prodDefaultConfig;
|
||||
};
|
||||
|
||||
// 当前应用配置
|
||||
const config = getRuntimeConfig();
|
||||
|
||||
// ============================================
|
||||
// 导出配置(向后兼容)
|
||||
// ============================================
|
||||
|
||||
// 单独导出常用配置项
|
||||
export const API_BASE_URL = config.api.baseUrl;
|
||||
export const FILE_DOWNLOAD_URL = config.file.downloadUrl;
|
||||
export const PUBLIC_IMG_PATH = config.publicImgPath;
|
||||
export const PUBLIC_WEB_PATH = config.publicWebPath;
|
||||
|
||||
// 导出完整配置对象
|
||||
export const APP_CONFIG = {
|
||||
// 应用标题
|
||||
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
|
||||
},
|
||||
|
||||
// 公共路径
|
||||
publicImgPath: config.publicImgPath,
|
||||
publicWebPath: config.publicWebPath,
|
||||
|
||||
// 功能开关
|
||||
features: config.features || {}
|
||||
};
|
||||
|
||||
// 默认导出
|
||||
export default APP_CONFIG;
|
||||
|
||||
Reference in New Issue
Block a user