Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4257f72799 | ||
|
|
46257ecf4a | ||
|
|
a2f57bc419 | ||
|
|
fe77c0ee1a | ||
|
|
98c46f4a7b |
@@ -31,8 +31,6 @@ jobs:
|
|||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
env:
|
|
||||||
SimApiVersion: ${{ github.ref_name }}
|
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
- name: Publish to npm
|
- name: Publish to npm
|
||||||
|
|||||||
@@ -336,25 +336,34 @@ 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
|
||||||
env:
|
- name: Build
|
||||||
SimApiVersion: ${{ github.ref_name }}
|
env:
|
||||||
run: npm run build
|
SimApiVersion: ${{ github.ref_name }} # 或其他版本号
|
||||||
|
run: npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
**调用方注入 AppVersion:**
|
**调用方注入 AppVersion:**
|
||||||
|
|||||||
Generated
+18
@@ -12,6 +12,7 @@
|
|||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^25.6.0",
|
||||||
"concurrently": "^9.2.1",
|
"concurrently": "^9.2.1",
|
||||||
"pinia": "^2.2.0",
|
"pinia": "^2.2.0",
|
||||||
"typescript": "~5.9.3",
|
"typescript": "~5.9.3",
|
||||||
@@ -433,6 +434,16 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/node": {
|
||||||
|
"version": "25.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.6.0.tgz",
|
||||||
|
"integrity": "sha512-+qIYRKdNYJwY3vRCZMdJbPLJAtGjQBudzZzdzwQYkEPQd+PJGixUL5QfvCLDaULoLv+RhT3LDkwEfKaAkgSmNQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"undici-types": "~7.19.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@vue/compiler-core": {
|
"node_modules/@vue/compiler-core": {
|
||||||
"version": "3.5.32",
|
"version": "3.5.32",
|
||||||
"resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.5.32.tgz",
|
"resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.5.32.tgz",
|
||||||
@@ -1004,6 +1015,13 @@
|
|||||||
"node": ">=14.17"
|
"node": ">=14.17"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/undici-types": {
|
||||||
|
"version": "7.19.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.19.2.tgz",
|
||||||
|
"integrity": "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/vite": {
|
"node_modules/vite": {
|
||||||
"version": "5.4.21",
|
"version": "5.4.21",
|
||||||
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.21.tgz",
|
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.21.tgz",
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^25.6.0",
|
||||||
"concurrently": "^9.2.1",
|
"concurrently": "^9.2.1",
|
||||||
"pinia": "^2.2.0",
|
"pinia": "^2.2.0",
|
||||||
"typescript": "~5.9.3",
|
"typescript": "~5.9.3",
|
||||||
|
|||||||
+18
-4
@@ -27,6 +27,7 @@ export type {
|
|||||||
} from './types'
|
} from './types'
|
||||||
|
|
||||||
declare const SimApiVersion: string;
|
declare const SimApiVersion: string;
|
||||||
|
declare const AppVersion: string;
|
||||||
// ── Helper: Fetch with Timeout ────────────────────────────────────────
|
// ── Helper: Fetch with Timeout ────────────────────────────────────────
|
||||||
|
|
||||||
function fetchWithTimeout(
|
function fetchWithTimeout(
|
||||||
@@ -203,7 +204,7 @@ export class SimApiCore {
|
|||||||
*/
|
*/
|
||||||
async getVersion(endpointName?: string): Promise<SimApiVersions> {
|
async getVersion(endpointName?: string): Promise<SimApiVersions> {
|
||||||
const versions: SimApiVersions = {
|
const versions: SimApiVersions = {
|
||||||
uiApp: '0.0.0-develop',
|
uiApp: typeof AppVersion === 'undefined' ? "0.0.0-develop" : AppVersion,
|
||||||
uiSimApi: typeof SimApiVersion === 'undefined' ? "0.0.0-develop" : SimApiVersion,
|
uiSimApi: typeof SimApiVersion === 'undefined' ? "0.0.0-develop" : SimApiVersion,
|
||||||
apiApp: '0.0.0',
|
apiApp: '0.0.0',
|
||||||
apiSimApi: '0.0.0',
|
apiSimApi: '0.0.0',
|
||||||
@@ -273,13 +274,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)
|
||||||
}
|
}
|
||||||
this.api.responseCallback.error(error)
|
// 网络/HTTP 错误:包装成标准响应格式抛出
|
||||||
|
if (!error?.code) {
|
||||||
|
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
|
||||||
},
|
},
|
||||||
|
|||||||
+4
-6
@@ -1,8 +1,7 @@
|
|||||||
import { defineConfig, loadEnv } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'))
|
||||||
export default defineConfig(({ mode }) => {
|
export default defineConfig(({ mode }) => {
|
||||||
const env = loadEnv(mode, process.cwd())
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
build: {
|
build: {
|
||||||
outDir: 'dist',
|
outDir: 'dist',
|
||||||
@@ -31,8 +30,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
// SimApiVersion 由环境变量注入
|
SimApiVersion: JSON.stringify(pkg.version)
|
||||||
'SimApiVersion': JSON.stringify(env.VITE_SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user