feat: 完成前端业务闭环与后端联调

This commit is contained in:
2026-08-24 23:37:56 +08:00
parent c59e36f933
commit 9ad572907b
175 changed files with 10711 additions and 1740 deletions
+8 -21
View File
@@ -1,13 +1,9 @@
const configuredMode = import.meta.env.VITE_JIAPU_RUNTIME_MODE || 'remote'
const configuredBaseUrl = import.meta.env.VITE_JIAPU_API_BASE_URL || 'https://backend-api.ddxcjp.cn'
const configuredClientId = import.meta.env.VITE_JIAPU_CLIENT_ID || '428a8310cd442757ae699df5d894f051'
const configuredTenantId = import.meta.env.VITE_JIAPU_TENANT_ID || '000000'
const configuredBaseUrl = 'https://backend-api.ddxcjp.cn'
const configuredClientId = '428a8310cd442757ae699df5d894f051'
const configuredTenantId = '000000'
if (!['mock', 'remote'].includes(configuredMode)) {
throw new Error('VITE_JIAPU_RUNTIME_MODE 只允许 mock 或 remote')
}
if (configuredMode === 'remote' && !/^https:\/\/[^\s/]+(?:\/[^\s]*)?$/.test(configuredBaseUrl)) {
throw new Error('VITE_JIAPU_API_BASE_URL 必须是 HTTPS 地址')
if (!/^https:\/\/[^\s/]+(?:\/[^\s]*)?$/.test(configuredBaseUrl)) {
throw new Error('正式服务地址必须使用 HTTPS')
}
if (configuredBaseUrl.endsWith('/')) {
throw new Error('VITE_JIAPU_API_BASE_URL 不能以斜杠结尾')
@@ -16,19 +12,10 @@ if (!configuredClientId || !configuredTenantId) {
throw new Error('远程服务的 clientId 和 tenantId 不能为空')
}
// 业务模块只消费这一不可变配置;不同构建环境通过 VITE_JIAPU_* 覆盖。
// 业务模块只消费这一不可变正式配置;测试替身在 API 服务边界注入,
// 不通过构建机环境变量改变正式包的服务端点。
export const runtimeConfig = Object.freeze({
mode: configuredMode,
baseUrl: configuredMode === 'remote' ? configuredBaseUrl : '',
baseUrl: configuredBaseUrl,
clientId: configuredClientId,
tenantId: configuredTenantId
})
export const isMockMode = () => runtimeConfig.mode === 'mock'
export const hasRemoteConfig = () => runtimeConfig.mode === 'remote' && Boolean(runtimeConfig.baseUrl && runtimeConfig.clientId)
export const resolveRuntimeMode = () => {
if (isMockMode()) return 'mock'
if (hasRemoteConfig()) return 'remote'
throw new Error('运行模式配置无效:只允许 mock 或配置完整的 remote')
}