修正无用的内容
Publish to npm / publish (push) Failing after 10s
Publish to npm / publish (push) Failing after 10s
This commit is contained in:
+20
-26
@@ -13,9 +13,8 @@ simapi-vue/
|
|||||||
│ ├── simapi.core.ts # 核心类 SimApiCore,零框架依赖
|
│ ├── simapi.core.ts # 核心类 SimApiCore,零框架依赖
|
||||||
│ └── simapi.pinia.ts # Pinia Store,Vue3 适配层
|
│ └── simapi.pinia.ts # Pinia Store,Vue3 适配层
|
||||||
├── dist/ # 构建产物
|
├── dist/ # 构建产物
|
||||||
├── package.json # exports: "/" → core, "/pinia" → vue
|
├── package.json # exports: "." → core, "/pinia" → vue
|
||||||
├── vite.core.config.ts # 构建 core → dist/index.mjs/cjs
|
├── vite.config.ts # 统一构建配置,生成 .mjs 和 .cjs
|
||||||
├── vite.pinia.config.ts # 构建 pinia → dist/pinia.mjs
|
|
||||||
└── tsconfig.build.json # tsc 生成类型声明
|
└── tsconfig.build.json # tsc 生成类型声明
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -43,10 +42,9 @@ SimApiBusinessCallback // { [code]: (data) => void },支持数字码或 'co
|
|||||||
- **无 Cookie**:所有请求使用 `credentials: 'omit'`,避免 CORS 问题
|
- **无 Cookie**:所有请求使用 `credentials: 'omit'`,避免 CORS 问题
|
||||||
- **Token 传递**:通过请求头 `Token` 传递认证信息
|
- **Token 传递**:通过请求头 `Token` 传递认证信息
|
||||||
- **超时控制**:通过 `fetchWithTimeout` 辅助函数实现
|
- **超时控制**:通过 `fetchWithTimeout` 辅助函数实现
|
||||||
- `setEndpoints()` 会自动调用 `fetchVersions()` 查询后端版本(`/versions`),打印到控制台
|
|
||||||
- `handleResponse()` 在响应非 200 时触发 `businessCallback`,不抛出异常
|
|
||||||
- `query()` 抛出异常的只有网络/HTTP 错误,业务错误码通过回调处理
|
- `query()` 抛出异常的只有网络/HTTP 错误,业务错误码通过回调处理
|
||||||
- `isLoggedIn` 是 getter,基于 localStorage 中的 token 判断
|
- `isLoggedIn` 是 getter,基于 localStorage 中的 token 判断
|
||||||
|
- **版本号**:`getVersion()` 返回的版本信息中,`uiSimApi` 由构建时注入的 `SimApiVersion` 填充,`uiApp` 由调用方的 `AppVersion` 填充(未注入时为 `0.0.0-develop`)
|
||||||
|
|
||||||
**修改建议**:
|
**修改建议**:
|
||||||
|
|
||||||
@@ -54,11 +52,11 @@ SimApiBusinessCallback // { [code]: (data) => void },支持数字码或 'co
|
|||||||
- 改 Token 存储:替换 `localStorage` 为 `sessionStorage` 或内存变量,修改 `getToken()`/`setToken()`/`removeToken()`
|
- 改 Token 存储:替换 `localStorage` 为 `sessionStorage` 或内存变量,修改 `getToken()`/`setToken()`/`removeToken()`
|
||||||
- 改登录/登出逻辑:修改 `login()`/`logout()` 方法
|
- 改登录/登出逻辑:修改 `login()`/`logout()` 方法
|
||||||
- 改超时处理:修改 `fetchWithTimeout()` 函数
|
- 改超时处理:修改 `fetchWithTimeout()` 函数
|
||||||
- **版本管理**:版本号通过 `declare const` 声明常量,构建时通过 Vite 的 `define` 注入。未指定时默认为 `0.0.0-dev`
|
- **版本管理**:版本号通过 `declare const` 声明常量,构建时通过 Vite 的 `define` 注入。未指定时默认为 `0.0.0-develop`
|
||||||
|
|
||||||
**autoInit 设计约束**:
|
**autoInit 设计约束**:
|
||||||
|
|
||||||
- 仅读取 `window.simapi` 的顶级字段:`endpoints`、`defaultEndpoint`、`debug`、`uiAppVersion`
|
- 仅读取 `window.simapi` 的顶级字段:`endpoints`、`defaultEndpoint`、`debug`
|
||||||
- 业务回调(`businessCallback`/`responseCallback`)不支持从 window 读取,必须在代码中通过 `setBusinessCallback` 注册
|
- 业务回调(`businessCallback`/`responseCallback`)不支持从 window 读取,必须在代码中通过 `setBusinessCallback` 注册
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -69,7 +67,7 @@ SimApiBusinessCallback // { [code]: (data) => void },支持数字码或 'co
|
|||||||
|
|
||||||
**关键设计**:
|
**关键设计**:
|
||||||
|
|
||||||
- **无独立状态**:state 中只有一个 `_core` 实例,不维护 `debug`、`versions`、`token` 等独立数据
|
- **无独立状态**:state 中只有一个 `_core` 实例,不维护 `debug`、`token` 等独立数据
|
||||||
- **单例 Core**:在 store state 中实例化 `SimApiCore`,整个应用共享一个实例
|
- **单例 Core**:在 store state 中实例化 `SimApiCore`,整个应用共享一个实例
|
||||||
- **纯代理映射**:所有 getters 直接映射到 `this._core` 的属性,所有 actions 直接调用 `this._core` 的方法
|
- **纯代理映射**:所有 getters 直接映射到 `this._core` 的属性,所有 actions 直接调用 `this._core` 的方法
|
||||||
- **响应式**:通过 Pinia 的响应式系统,当 core 状态变化时自动更新
|
- **响应式**:通过 Pinia 的响应式系统,当 core 状态变化时自动更新
|
||||||
@@ -92,7 +90,7 @@ api.configure({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 所有方法与 SimApiCore 完全一致
|
// 所有方法与 SimApiCore 完全一致
|
||||||
await api.query('/users/list', { page:1 })
|
await api.query('/users/list', { page: 1 })
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -101,39 +99,33 @@ await api.query('/users/list', { page:1 })
|
|||||||
|
|
||||||
```
|
```
|
||||||
npm run build
|
npm run build
|
||||||
→ vite build vite.core.config.ts 输出 dist/index.mjs / index.cjs
|
→ vite build 输出 dist/index.mjs / index.cjs / pinia.mjs / pinia.cjs
|
||||||
→ vite build vite.pinia.config.ts 输出 dist/pinia.mjs
|
→ tsc -p tsconfig.build.json 输出 *.d.ts 类型声明
|
||||||
→ tsc -p tsconfig.build.json 输出 *.d.ts 类型声明
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**版本号注入:**
|
**版本号注入:**
|
||||||
|
|
||||||
版本号通过 `vite.core.config.ts` 的 `define` 配置注入,从 npm config 读取:
|
版本号通过 `vite.config.ts` 的 `define` 配置注入,从 npm config 读取:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
define: {
|
define: {
|
||||||
'AppVersion': JSON.stringify(process.env.npm_config_AppVersion || '0.0.0-develop'),
|
|
||||||
'SimApiVersion': JSON.stringify(process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
'SimApiVersion': JSON.stringify(process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**本地构建示例:**
|
**本地构建示例:**
|
||||||
```bash
|
```bash
|
||||||
# 通过 npm config 传递(推荐)
|
# 通过环境变量
|
||||||
npm run build -- --AppVersion=1.0.0 --SimApiVersion=1.0.0
|
|
||||||
|
|
||||||
# 或通过环境变量
|
|
||||||
# Windows PowerShell
|
# Windows PowerShell
|
||||||
$env:AppVersion="1.0.0"; $env:SimApiVersion="1.0.0"; npm run build
|
$env:npm_config_SimApiVersion='1.0.0'; npm run build
|
||||||
|
|
||||||
# Linux/Mac
|
# Linux/Mac
|
||||||
AppVersion=1.0.0 SimApiVersion=1.0.0 npm run build
|
npm_config_SimApiVersion=1.0.0 npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
**GitHub Actions 自动发布:**
|
**GitHub Actions 自动发布:**
|
||||||
```yaml
|
```yaml
|
||||||
env:
|
env:
|
||||||
AppVersion: ${{ github.ref_name }}
|
|
||||||
SimApiVersion: ${{ github.ref_name }}
|
SimApiVersion: ${{ github.ref_name }}
|
||||||
run: npm run build
|
run: npm run build
|
||||||
```
|
```
|
||||||
@@ -142,9 +134,10 @@ run: npm run build
|
|||||||
|
|
||||||
```
|
```
|
||||||
dist/
|
dist/
|
||||||
├── index.mjs # core ESM (5.59 KB)
|
├── index.mjs # core ESM
|
||||||
├── index.cjs # core CJS (4.15 KB)
|
├── index.cjs # core CJS
|
||||||
├── pinia.mjs # pinia ESM (6.81 KB)
|
├── pinia.mjs # pinia ESM
|
||||||
|
├── pinia.cjs # pinia CJS
|
||||||
├── simapi.core.d.ts
|
├── simapi.core.d.ts
|
||||||
├── simapi.pinia.d.ts
|
├── simapi.pinia.d.ts
|
||||||
└── types.d.ts
|
└── types.d.ts
|
||||||
@@ -155,7 +148,7 @@ dist/
|
|||||||
## package.json exports
|
## package.json exports
|
||||||
|
|
||||||
```json
|
```json
|
||||||
".": { "import": "./dist/index.mjs", "require": "./dist/index.cjs", "types": "./dist/simapi.core.d.ts" }
|
".": { "import": "./dist/index.mjs", "types": "./dist/simapi.core.d.ts" }
|
||||||
"./pinia": { "import": "./dist/pinia.mjs", "types": "./dist/simapi.pinia.d.ts" }
|
"./pinia": { "import": "./dist/pinia.mjs", "types": "./dist/simapi.pinia.d.ts" }
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -169,4 +162,5 @@ dist/
|
|||||||
- **无 Cookie**:所有请求不发送 Cookie,Token 通过请求头传递
|
- **无 Cookie**:所有请求不发送 Cookie,Token 通过请求头传递
|
||||||
- **零依赖**:不需要安装 axios,使用原生 fetch
|
- **零依赖**:不需要安装 axios,使用原生 fetch
|
||||||
- 删除了 Angular 支持,如需恢复参考 git 历史
|
- 删除了 Angular 支持,如需恢复参考 git 历史
|
||||||
- **版本号管理**:使用 `declare const` + Vite `define` 注入,不再需要 sed 替换脚本
|
- **版本号管理**:使用 `declare const` + Vite `define` 注入
|
||||||
|
- **AppVersion** 不注入,留给调用方自己管理
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ await api.query('/stats', {}, 'admin')
|
|||||||
|
|
||||||
## autoInit — 从 window 读取配置
|
## autoInit — 从 window 读取配置
|
||||||
|
|
||||||
支持字段:`endpoints`、`defaultEndpoint`、`debug`、`uiAppVersion`。业务回调需在代码中通过 `setBusinessCallback` 处理。
|
支持字段:`endpoints`、`defaultEndpoint`、`debug`。业务回调需在代码中通过 `setBusinessCallback` 处理。
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script>
|
<script>
|
||||||
@@ -153,9 +153,6 @@ interface SimApiOptions {
|
|||||||
/** 调试模式,默认 true */
|
/** 调试模式,默认 true */
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
|
|
||||||
/** UI 应用版本,如果不指定则使用库内置的版本号 */
|
|
||||||
uiAppVersion?: string
|
|
||||||
|
|
||||||
/** 认证相关配置 */
|
/** 认证相关配置 */
|
||||||
auth?: Partial<SimApiAuthConfig>
|
auth?: Partial<SimApiAuthConfig>
|
||||||
|
|
||||||
@@ -308,7 +305,7 @@ api.configure({
|
|||||||
| 方法/属性 | 说明 |
|
| 方法/属性 | 说明 |
|
||||||
|-----------|------|
|
|-----------|------|
|
||||||
| `configure(options)` | 批量配置(深合并) |
|
| `configure(options)` | 批量配置(深合并) |
|
||||||
| `autoInit()` | 从 `window.simapi` 读取配置(endpoints、defaultEndpoint、debug、uiAppVersion) |
|
| `autoInit()` | 从 `window.simapi` 读取配置(endpoints、defaultEndpoint、debug) |
|
||||||
| `setEndpoints(map)` | 设置端点 |
|
| `setEndpoints(map)` | 设置端点 |
|
||||||
| `setBusinessCallback(code, fn)` | 注册业务错误码回调 |
|
| `setBusinessCallback(code, fn)` | 注册业务错误码回调 |
|
||||||
| `query(uri, params?, endpointKey?, headers?)` | POST 请求,返回 `Promise<SimApiBaseResponse<T>>` |
|
| `query(uri, params?, endpointKey?, headers?)` | POST 请求,返回 `Promise<SimApiBaseResponse<T>>` |
|
||||||
@@ -321,7 +318,6 @@ api.configure({
|
|||||||
| `removeToken()` | 清除 Token |
|
| `removeToken()` | 清除 Token |
|
||||||
| `isLoggedIn` | getter,是否已登录 |
|
| `isLoggedIn` | getter,是否已登录 |
|
||||||
| `debug` | boolean,调试模式 |
|
| `debug` | boolean,调试模式 |
|
||||||
| `uiAppVersion` | UI 应用版本号(可选配置) |
|
|
||||||
| `logDebug(...args)` | 日志工具(仅在 debug 模式输出) |
|
| `logDebug(...args)` | 日志工具(仅在 debug 模式输出) |
|
||||||
|
|
||||||
## 构建
|
## 构建
|
||||||
@@ -334,29 +330,42 @@ npm link # 本地调试
|
|||||||
|
|
||||||
### 版本号注入
|
### 版本号注入
|
||||||
|
|
||||||
库使用 `declare const` 声明版本常量,构建时通过 Vite 的 `define` 注入版本号:
|
库使用 `declare const` 声明版本常量,构建时通过 Vite 的 `define` 注入版本号。
|
||||||
|
|
||||||
|
**注意:**
|
||||||
|
- **SimApiVersion**:由 simapi 库构建时注入
|
||||||
|
- **AppVersion**:不注入,留给调用方 APP 注入
|
||||||
|
|
||||||
|
**本地构建:**
|
||||||
|
|
||||||
**本地构建:**
|
|
||||||
```bash
|
```bash
|
||||||
# 通过 npm config 传递
|
# 通过环境变量注入 SimApiVersion
|
||||||
npm run build -- --AppVersion=1.0.0 --SimApiVersion=1.0.0
|
|
||||||
|
|
||||||
# 或设置环境变量后构建
|
|
||||||
# Windows PowerShell
|
# Windows PowerShell
|
||||||
$env:AppVersion="1.0.0"; $env:SimApiVersion="1.0.0"; npm run build
|
$env:npm_config_SimApiVersion='1.0.0'; npm run build
|
||||||
|
|
||||||
# Linux/Mac
|
# Linux/Mac
|
||||||
AppVersion=1.0.0 SimApiVersion=1.0.0 npm run build
|
npm_config_SimApiVersion=1.0.0 npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
**CI/CD 构建版本号:**
|
未指定时默认为 `0.0.0-develop`。
|
||||||
```bash
|
|
||||||
|
**CI/CD 构建版本号:**
|
||||||
|
|
||||||
|
```yaml
|
||||||
env:
|
env:
|
||||||
AppVersion: ${{ github.ref_name }}
|
|
||||||
SimApiVersion: ${{ github.ref_name }}
|
SimApiVersion: ${{ github.ref_name }}
|
||||||
|
run: npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
如果未指定环境变量,版本号默认为 `0.0.0-develop`。
|
**调用方注入 AppVersion:**
|
||||||
|
|
||||||
|
调用方在自己的 `vite.config.ts` 中添加:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
define: {
|
||||||
|
'AppVersion': JSON.stringify('1.0.0')
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
Generated
+310
-17
@@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "@simcu/simapi",
|
"name": "@simcu/simapi",
|
||||||
"version": "0.0.0-version-placeholder",
|
"version": "0.0.0-develop",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@simcu/simapi",
|
"name": "@simcu/simapi",
|
||||||
"version": "0.0.0-version-placeholder",
|
"version": "0.0.0-develop",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^5.0.0",
|
"concurrently": "^9.2.1",
|
||||||
"pinia": "^2.2.0",
|
"pinia": "^2.2.0",
|
||||||
"typescript": "~5.9.3",
|
"typescript": "~5.9.3",
|
||||||
"vite": "^5.0.0",
|
"vite": "^5.0.0",
|
||||||
@@ -433,20 +433,6 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@vitejs/plugin-vue": {
|
|
||||||
"version": "5.2.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-5.2.4.tgz",
|
|
||||||
"integrity": "sha512-7Yx/SXSOcQq5HiiV3orevHUFn+pmMB4cgbEkDYgnkUWb0WfeQ/wa2yFv6D5ICiCQOVpjA7vYDXrC7AGO8yjDHA==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": "^18.0.0 || >=20.0.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"vite": "^5.0.0 || ^6.0.0",
|
|
||||||
"vue": "^3.2.25"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"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",
|
||||||
@@ -563,6 +549,122 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/ansi-regex": {
|
||||||
|
"version": "5.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||||
|
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/ansi-styles": {
|
||||||
|
"version": "4.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||||
|
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"color-convert": "^2.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk": {
|
||||||
|
"version": "4.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
||||||
|
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^4.1.0",
|
||||||
|
"supports-color": "^7.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chalk/node_modules/supports-color": {
|
||||||
|
"version": "7.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||||
|
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"has-flag": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/cliui": {
|
||||||
|
"version": "8.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
|
||||||
|
"integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"string-width": "^4.2.0",
|
||||||
|
"strip-ansi": "^6.0.1",
|
||||||
|
"wrap-ansi": "^7.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/color-convert": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"color-name": "~1.1.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=7.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/color-name": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/concurrently": {
|
||||||
|
"version": "9.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/concurrently/-/concurrently-9.2.1.tgz",
|
||||||
|
"integrity": "sha512-fsfrO0MxV64Znoy8/l1vVIjjHa29SZyyqPgQBwhiDcaW8wJc2W3XWVOGx4M3oJBnv/zdUZIIp1gDeS98GzP8Ng==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "4.1.2",
|
||||||
|
"rxjs": "7.8.2",
|
||||||
|
"shell-quote": "1.8.3",
|
||||||
|
"supports-color": "8.1.1",
|
||||||
|
"tree-kill": "1.2.2",
|
||||||
|
"yargs": "17.7.2"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"conc": "dist/bin/concurrently.js",
|
||||||
|
"concurrently": "dist/bin/concurrently.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/open-cli-tools/concurrently?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/csstype": {
|
"node_modules/csstype": {
|
||||||
"version": "3.2.3",
|
"version": "3.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
||||||
@@ -570,6 +672,13 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/emoji-regex": {
|
||||||
|
"version": "8.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
||||||
|
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/entities": {
|
"node_modules/entities": {
|
||||||
"version": "7.0.1",
|
"version": "7.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
|
||||||
@@ -583,6 +692,16 @@
|
|||||||
"url": "https://github.com/fb55/entities?sponsor=1"
|
"url": "https://github.com/fb55/entities?sponsor=1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/escalade": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/estree-walker": {
|
"node_modules/estree-walker": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
|
||||||
@@ -605,6 +724,36 @@
|
|||||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/get-caller-file": {
|
||||||
|
"version": "2.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
||||||
|
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": "6.* || 8.* || >= 10.*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/has-flag": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/is-fullwidth-code-point": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/magic-string": {
|
"node_modules/magic-string": {
|
||||||
"version": "0.30.21",
|
"version": "0.30.21",
|
||||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
|
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
|
||||||
@@ -693,6 +842,16 @@
|
|||||||
"node": "^10 || ^12 || >=14"
|
"node": "^10 || ^12 || >=14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/require-directory": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/rollup": {
|
"node_modules/rollup": {
|
||||||
"version": "4.60.1",
|
"version": "4.60.1",
|
||||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.60.1.tgz",
|
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.60.1.tgz",
|
||||||
@@ -738,6 +897,29 @@
|
|||||||
"fsevents": "~2.3.2"
|
"fsevents": "~2.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/rxjs": {
|
||||||
|
"version": "7.8.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz",
|
||||||
|
"integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/shell-quote": {
|
||||||
|
"version": "1.8.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.3.tgz",
|
||||||
|
"integrity": "sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/source-map-js": {
|
"node_modules/source-map-js": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
||||||
@@ -748,6 +930,60 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/string-width": {
|
||||||
|
"version": "4.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||||
|
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"emoji-regex": "^8.0.0",
|
||||||
|
"is-fullwidth-code-point": "^3.0.0",
|
||||||
|
"strip-ansi": "^6.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/strip-ansi": {
|
||||||
|
"version": "6.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||||
|
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-regex": "^5.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/supports-color": {
|
||||||
|
"version": "8.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",
|
||||||
|
"integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"has-flag": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/supports-color?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tree-kill": {
|
||||||
|
"version": "1.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz",
|
||||||
|
"integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"tree-kill": "cli.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/tslib": {
|
"node_modules/tslib": {
|
||||||
"version": "2.8.1",
|
"version": "2.8.1",
|
||||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
||||||
@@ -1306,6 +1542,63 @@
|
|||||||
"optional": true
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/wrap-ansi": {
|
||||||
|
"version": "7.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
|
||||||
|
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^4.0.0",
|
||||||
|
"string-width": "^4.1.0",
|
||||||
|
"strip-ansi": "^6.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/y18n": {
|
||||||
|
"version": "5.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
||||||
|
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/yargs": {
|
||||||
|
"version": "17.7.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
||||||
|
"integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"cliui": "^8.0.1",
|
||||||
|
"escalade": "^3.1.1",
|
||||||
|
"get-caller-file": "^2.0.5",
|
||||||
|
"require-directory": "^2.1.1",
|
||||||
|
"string-width": "^4.2.3",
|
||||||
|
"y18n": "^5.0.5",
|
||||||
|
"yargs-parser": "^21.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/yargs-parser": {
|
||||||
|
"version": "21.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
|
||||||
|
"integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-7
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@simcu/simapi",
|
"name": "@simcu/simapi",
|
||||||
"version": "0.0.0-version-placeholder",
|
"version": "0.0.0-develop",
|
||||||
"description": "SimApi 统一前端 HTTP 客户端库,支持 Vue3 和常规 JS/TS 项目(基于原生 fetch)",
|
"description": "SimApi 统一前端 HTTP 客户端库,支持 Vue3 和常规 JS/TS 项目(基于原生 fetch)",
|
||||||
"author": "simcu",
|
"author": "simcu",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": "./dist/index.mjs",
|
"import": "./dist/index.mjs",
|
||||||
"require": "./dist/index.cjs",
|
|
||||||
"types": "./dist/simapi.core.d.ts"
|
"types": "./dist/simapi.core.d.ts"
|
||||||
},
|
},
|
||||||
"./pinia": {
|
"./pinia": {
|
||||||
@@ -31,14 +30,11 @@
|
|||||||
"types": "./dist/simapi.pinia.d.ts"
|
"types": "./dist/simapi.pinia.d.ts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"main": "./dist/index.cjs",
|
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
"types": "./dist/simapi.core.d.ts",
|
"types": "./dist/simapi.core.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run build:core && npm run build:pinia && npm run types",
|
"build": "vite build && npm run types",
|
||||||
"build:core": "vite build --config vite.core.config.ts",
|
"dev": "vite build --watch",
|
||||||
"build:pinia": "vite build --config vite.pinia.config.ts",
|
|
||||||
"dev": "vite build --config vite.core.config.ts --watch",
|
|
||||||
"types": "tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
|
"types": "tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
|
||||||
"lint": "tsc --noEmit"
|
"lint": "tsc --noEmit"
|
||||||
},
|
},
|
||||||
@@ -46,6 +42,7 @@
|
|||||||
"tslib": "^2.3.0"
|
"tslib": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"concurrently": "^9.2.1",
|
||||||
"pinia": "^2.2.0",
|
"pinia": "^2.2.0",
|
||||||
"typescript": "~5.9.3",
|
"typescript": "~5.9.3",
|
||||||
"vite": "^5.0.0",
|
"vite": "^5.0.0",
|
||||||
|
|||||||
+14
-18
@@ -26,7 +26,6 @@ export type {
|
|||||||
SimApiBaseResponse,
|
SimApiBaseResponse,
|
||||||
} from './types'
|
} from './types'
|
||||||
|
|
||||||
declare const AppVersion: string;
|
|
||||||
declare const SimApiVersion: string;
|
declare const SimApiVersion: string;
|
||||||
// ── Helper: Fetch with Timeout ────────────────────────────────────────
|
// ── Helper: Fetch with Timeout ────────────────────────────────────────
|
||||||
|
|
||||||
@@ -107,7 +106,7 @@ export class SimApiCore {
|
|||||||
/**
|
/**
|
||||||
* 从 window.simapi 读取配置并初始化
|
* 从 window.simapi 读取配置并初始化
|
||||||
*
|
*
|
||||||
* 支持字段:endpoints, defaultEndpoint, debug, uiAppVersion
|
* 支持字段:endpoints, defaultEndpoint, debug
|
||||||
* 业务回调(businessCallback / responseCallback)需在代码中处理
|
* 业务回调(businessCallback / responseCallback)需在代码中处理
|
||||||
*/
|
*/
|
||||||
autoInit(): void {
|
autoInit(): void {
|
||||||
@@ -203,18 +202,22 @@ export class SimApiCore {
|
|||||||
* const versions = await api.getVersion('backup')
|
* const versions = await api.getVersion('backup')
|
||||||
*/
|
*/
|
||||||
async getVersion(endpointName?: string): Promise<SimApiVersions> {
|
async getVersion(endpointName?: string): Promise<SimApiVersions> {
|
||||||
|
const versions: SimApiVersions = {
|
||||||
|
uiApp: '0.0.0-develop',
|
||||||
|
uiSimApi: typeof SimApiVersion === 'undefined' ? "0.0.0-develop" : SimApiVersion,
|
||||||
|
apiApp: '0.0.0',
|
||||||
|
apiSimApi: '0.0.0',
|
||||||
|
apiAppFull: '0.0.0',
|
||||||
|
apiSimApiFull: '0.0.0',
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
const resp = await this.query<any>('/versions', {}, endpointName)
|
const resp = await this.query<any>('/versions', {}, endpointName)
|
||||||
if (resp?.data) {
|
if (resp?.data) {
|
||||||
const d = resp.data
|
const d = resp.data
|
||||||
const versions: SimApiVersions = {
|
versions.apiApp= d.App?.split('+')[0] ?? '0.0.0';
|
||||||
uiApp: AppVersion ?? "0.0.0-develop",
|
versions.apiSimApi= d.SimApi?.split('+')[0] ?? '0.0.0';
|
||||||
uiSimApi: SimApiVersion ?? "0.0.0-develop",
|
versions.apiAppFull= d.App ?? '0.0.0';
|
||||||
apiApp: d.App?.split('+')[0] ?? '0.0.0',
|
versions.apiSimApiFull= d.SimApi ?? '0.0.0';
|
||||||
apiSimApi: d.SimApi?.split('+')[0] ?? '0.0.0',
|
|
||||||
apiAppFull: d.App ?? '0.0.0',
|
|
||||||
apiSimApiFull: d.SimApi ?? '0.0.0',
|
|
||||||
}
|
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.log(`UI主应用版本: ${versions.uiApp}\nUISimApi版本: ${versions.uiSimApi}\nAPI主应用版本: ${versions.apiApp}\nAPISimApi版本: ${versions.apiSimApi}`)
|
console.log(`UI主应用版本: ${versions.uiApp}\nUISimApi版本: ${versions.uiSimApi}\nAPI主应用版本: ${versions.apiApp}\nAPISimApi版本: ${versions.apiSimApi}`)
|
||||||
}
|
}
|
||||||
@@ -223,14 +226,7 @@ export class SimApiCore {
|
|||||||
} catch {
|
} catch {
|
||||||
// 版本获取失败返回默认值
|
// 版本获取失败返回默认值
|
||||||
}
|
}
|
||||||
return {
|
return versions;
|
||||||
uiApp: "0.0.0-develop",
|
|
||||||
uiSimApi: "0.0.0-develop",
|
|
||||||
apiApp: '0.0.0',
|
|
||||||
apiSimApi: '0.0.0',
|
|
||||||
apiAppFull: '0.0.0',
|
|
||||||
apiSimApiFull: '0.0.0',
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async query<T = any>(
|
async query<T = any>(
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ export interface SimApiApiConfig {
|
|||||||
/** SimApi 完整配置 */
|
/** SimApi 完整配置 */
|
||||||
export interface SimApiOptions {
|
export interface SimApiOptions {
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
/** UI 应用版本,如果不指定则使用库内置的版本号 */
|
|
||||||
uiAppVersion?: string
|
|
||||||
auth?: Partial<SimApiAuthConfig>
|
auth?: Partial<SimApiAuthConfig>
|
||||||
api?: Partial<SimApiApiConfig>
|
api?: Partial<SimApiApiConfig>
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -17,5 +17,6 @@
|
|||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true
|
"emitDecoratorMetadata": true
|
||||||
},
|
},
|
||||||
"include": ["src/types.ts", "src/simapi.core.ts", "src/simapi.pinia.ts"]
|
"include": ["src/types.ts", "src/simapi.core.ts", "src/simapi.pinia.ts"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
|
|
||||||
|
export default defineConfig(({ mode }) => {
|
||||||
|
const env = loadEnv(mode, process.cwd())
|
||||||
|
|
||||||
|
return {
|
||||||
|
build: {
|
||||||
|
outDir: 'dist',
|
||||||
|
emptyOutDir: true,
|
||||||
|
lib: {
|
||||||
|
entry: ['src/simapi.core.ts', 'src/simapi.pinia.ts'],
|
||||||
|
name: 'SimApi',
|
||||||
|
formats: ['es', 'cjs'],
|
||||||
|
fileName: (format, entryName) => {
|
||||||
|
if (entryName === 'simapi.core') {
|
||||||
|
return `index.${format === 'es' ? 'mjs' : 'cjs'}`
|
||||||
|
} else if (entryName === 'simapi.pinia') {
|
||||||
|
return `pinia.${format === 'es' ? 'mjs' : 'cjs'}`
|
||||||
|
}
|
||||||
|
return `${entryName}.${format === 'es' ? 'mjs' : 'cjs'}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rollupOptions: {
|
||||||
|
external: ['vue', 'pinia'],
|
||||||
|
output: {
|
||||||
|
globals: {
|
||||||
|
vue: 'Vue',
|
||||||
|
pinia: 'Pinia'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
// SimApiVersion 由环境变量注入
|
||||||
|
'SimApiVersion': JSON.stringify(env.VITE_SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import { defineConfig } from 'vite'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
build: {
|
|
||||||
outDir: 'dist',
|
|
||||||
emptyOutDir: true,
|
|
||||||
lib: {
|
|
||||||
entry: 'src/simapi.core.ts',
|
|
||||||
name: 'SimApiCore',
|
|
||||||
formats: ['es', 'cjs'],
|
|
||||||
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'cjs'}`
|
|
||||||
},
|
|
||||||
rollupOptions: {
|
|
||||||
// 不再需要 external,使用原生 fetch
|
|
||||||
}
|
|
||||||
},
|
|
||||||
define: {
|
|
||||||
// SimApiVersion 由构建注入,AppVersion 留给调用方 APP 注入
|
|
||||||
// 使用方式: npm run build -- --SimApiVersion=1.0.0
|
|
||||||
'SimApiVersion': JSON.stringify(process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import { defineConfig } from 'vite'
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
build: {
|
|
||||||
outDir: 'dist',
|
|
||||||
emptyOutDir: false,
|
|
||||||
lib: {
|
|
||||||
entry: 'src/simapi.pinia.ts',
|
|
||||||
name: 'SimApiPinia',
|
|
||||||
formats: ['es'],
|
|
||||||
fileName: () => 'pinia.mjs'
|
|
||||||
},
|
|
||||||
rollupOptions: {
|
|
||||||
external: ['vue', 'pinia'],
|
|
||||||
output: {
|
|
||||||
globals: {
|
|
||||||
vue: 'Vue',
|
|
||||||
pinia: 'Pinia'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user