rentease-app/config/index.js

137 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 全局配置文件
* 统一管理应用配置信息
*/
// 环境配置
const ENV = {
// 开发环境
DEVELOPMENT: 'development',
// 生产环境
PRODUCTION: 'production',
// 测试环境
TEST: 'test'
}
// 当前环境
const currentEnv = ENV.DEVELOPMENT
// 基础配置
const config = {
// 应用信息
app: {
name: 'RentEase',
version: '1.0.0',
description: '智能租赁管理平台'
},
// API配置
api: {
// 开发环境
development: {
baseUrl: 'http://localhost:3000/api',
timeout: 30000,
retry: 1
},
// 生产环境
production: {
baseUrl: 'https://api.rentease.com/api',
timeout: 30000,
retry: 2
},
// 测试环境
test: {
baseUrl: 'http://test-api.rentease.com/api',
timeout: 30000,
retry: 1
}
},
// 存储键名配置
storage: {
token: 'token',
userInfo: 'userInfo',
tenantInfo: 'tenantInfo',
menus: 'menus',
savedUser: 'savedUser',
settings: 'settings'
},
// 分页配置
pagination: {
page: 1,
pageSize: 10,
pageSizeOptions: [10, 20, 50, 100]
},
// 状态码配置
statusCode: {
SUCCESS: 200,
BAD_REQUEST: 400,
UNAUTHORIZED: 401,
FORBIDDEN: 403,
NOT_FOUND: 404,
SERVER_ERROR: 500
},
// 正则表达式配置
regex: {
// 手机号
phone: /^1[3-9]\d{9}$/,
// 邮箱
email: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
// 密码至少6位
password: /^.{6,}$/,
// 用户名3-20位字母数字下划线
username: /^[a-zA-Z0-9_]{3,20}$/,
// 金额最多2位小数
amount: /^\d+(\.\d{1,2})?$/
}
}
/**
* 获取当前环境配置
*/
export const getCurrentConfig = () => {
return {
...config.api[currentEnv],
env: currentEnv
}
}
/**
* 获取API基础URL
*/
export const getBaseUrl = () => {
return config.api[currentEnv].baseUrl
}
/**
* 获取请求超时时间
*/
export const getTimeout = () => {
return config.api[currentEnv].timeout
}
/**
* 获取存储键名
*/
export const getStorageKey = (key) => {
return config.storage[key] || key
}
/**
* 验证正则
*/
export const validate = (type, value) => {
const regex = config.regex[type]
return regex ? regex.test(value) : false
}
/**
* 获取状态码配置
*/
export const statusCode = config.statusCode
export default config