Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe77c0ee1a | ||
|
|
98c46f4a7b |
@@ -336,24 +336,33 @@ npm link # 本地调试
|
|||||||
- **SimApiVersion**:由 simapi 库构建时注入
|
- **SimApiVersion**:由 simapi 库构建时注入
|
||||||
- **AppVersion**:不注入,留给调用方 APP 注入
|
- **AppVersion**:不注入,留给调用方 APP 注入
|
||||||
|
|
||||||
|
**支持的版本号环境变量(按优先级):**
|
||||||
|
|
||||||
|
1. `VITE_SimApiVersion` — Vite .env 文件
|
||||||
|
2. `npm_config_SimApiVersion` — npm 构建时通过 `npm run build` 前设置
|
||||||
|
3. `SimApiVersion` — 直接环境变量(如 GitHub Actions)
|
||||||
|
|
||||||
|
未指定时默认为 `0.0.0-develop`。
|
||||||
|
|
||||||
**本地构建:**
|
**本地构建:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 通过环境变量注入 SimApiVersion
|
|
||||||
# Windows PowerShell
|
# Windows PowerShell
|
||||||
$env:npm_config_SimApiVersion='1.0.0'; npm run build
|
$env:npm_config_SimApiVersion='1.0.0'; npm run build
|
||||||
|
|
||||||
|
# Windows CMD
|
||||||
|
set npm_config_SimApiVersion=1.0.0 && npm run build
|
||||||
|
|
||||||
# Linux/Mac
|
# Linux/Mac
|
||||||
npm_config_SimApiVersion=1.0.0 npm run build
|
npm_config_SimApiVersion=1.0.0 npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
未指定时默认为 `0.0.0-develop`。
|
**GitHub Actions / CI/CD:**
|
||||||
|
|
||||||
**CI/CD 构建版本号:**
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
- name: Build
|
||||||
env:
|
env:
|
||||||
SimApiVersion: ${{ github.ref_name }}
|
SimApiVersion: ${{ github.ref_name }} # 或其他版本号
|
||||||
run: npm run build
|
run: npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+15
-2
@@ -273,13 +273,26 @@ export class SimApiCore {
|
|||||||
this.api.businessCallback['common'](processedData)
|
this.api.businessCallback['common'](processedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 直接返回,不再根据 code 抛出错误
|
// code != 200 时抛出业务错误
|
||||||
|
if (processedData.code !== 200) {
|
||||||
|
throw processedData
|
||||||
|
}
|
||||||
return processedData
|
return processedData
|
||||||
} catch (error) {
|
|
||||||
|
} catch (error: any) {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.log('[RESPONSE]', queryId, '->', error)
|
console.log('[RESPONSE]', queryId, '->', error)
|
||||||
}
|
}
|
||||||
|
// 网络/HTTP 错误:包装成标准响应格式抛出
|
||||||
|
if (!error?.code) {
|
||||||
this.api.responseCallback.error(error)
|
this.api.responseCallback.error(error)
|
||||||
|
throw {
|
||||||
|
code: -1,
|
||||||
|
message: error?.message || '网络错误',
|
||||||
|
data: error,
|
||||||
|
} as SimApiBaseResponse<T>
|
||||||
|
}
|
||||||
|
// 业务错误直接抛出
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
"noUnusedLocals": false,
|
"noUnusedLocals": false,
|
||||||
"noUnusedParameters": false,
|
"noUnusedParameters": false,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": false,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true
|
"emitDecoratorMetadata": true
|
||||||
},
|
},
|
||||||
|
|||||||
+10
-2
@@ -31,8 +31,16 @@ export default defineConfig(({ mode }) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
// SimApiVersion 由环境变量注入
|
// SimApiVersion 由环境变量注入,支持:
|
||||||
'SimApiVersion': JSON.stringify(env.VITE_SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
// - VITE_SimApiVersion (Vite .env 文件)
|
||||||
|
// - npm_config_SimApiVersion (npm 构建时)
|
||||||
|
// - SimApiVersion (直接环境变量,如 GitHub Actions)
|
||||||
|
'SimApiVersion': JSON.stringify(
|
||||||
|
env.VITE_SimApiVersion ||
|
||||||
|
process.env.npm_config_SimApiVersion ||
|
||||||
|
process.env.SimApiVersion ||
|
||||||
|
'0.0.0-develop'
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user