@lovrabet/sdk 1.1.15 → 1.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +200 -29
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/src/models/abstract-base-model.d.ts +4 -3
- package/dist/src/models/openapi-model.d.ts +7 -1
- package/dist/src/models/webapi-model.d.ts +2 -1
- package/dist/src/types/index.d.ts +70 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseModelMethods, ListParams, ListResponse, ModelConfig, ClientConfig } from '../types';
|
|
1
|
+
import type { BaseModelMethods, ListParams, ListResponse, ModelConfig, ClientConfig, SortList, SelectOption, SelectOptionsParams } from '../types';
|
|
2
2
|
import type { HttpClient } from '../http/http-client';
|
|
3
3
|
/**
|
|
4
4
|
* 抽象基础模型类
|
|
@@ -13,13 +13,14 @@ export declare abstract class AbstractBaseModel implements BaseModelMethods {
|
|
|
13
13
|
constructor(modelName: string, httpClient: HttpClient, globalConfig: ClientConfig);
|
|
14
14
|
private resolveModelConfig;
|
|
15
15
|
protected abstract getApiPath(method: string): string;
|
|
16
|
-
protected abstract buildRequestBody(method: string, data: any): any;
|
|
17
|
-
getList<T = any>(params?: ListParams): Promise<ListResponse<T>>;
|
|
16
|
+
protected abstract buildRequestBody(method: string, data: any, sortList?: SortList): any;
|
|
17
|
+
getList<T = any>(params?: ListParams, sortList?: SortList): Promise<ListResponse<T>>;
|
|
18
18
|
getOne<T = any>(id: string | number): Promise<T>;
|
|
19
19
|
create<T = any>(data: Record<string, any>): Promise<T>;
|
|
20
20
|
update<T = any>(id: string | number, data: Record<string, any>): Promise<T>;
|
|
21
21
|
delete(id: string | number): Promise<void>;
|
|
22
22
|
getDatasetList<T = any>(): Promise<T[]>;
|
|
23
|
+
getSelectOptions(params: SelectOptionsParams): Promise<SelectOption[]>;
|
|
23
24
|
private isOpenApiMode;
|
|
24
25
|
getConfig(): ModelConfig;
|
|
25
26
|
getModelName(): string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbstractBaseModel } from './abstract-base-model';
|
|
2
|
+
import type { SortList } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* OpenAPI 模型实现
|
|
4
5
|
* 处理 OpenAPI 模式下的 URL 生成和请求体构建
|
|
@@ -13,5 +14,10 @@ export declare class OpenApiModel extends AbstractBaseModel {
|
|
|
13
14
|
* 认证信息(token、timeStamp)由 HttpClient 自动添加到请求头(Header)中
|
|
14
15
|
* 请求体只包含业务数据
|
|
15
16
|
*/
|
|
16
|
-
protected buildRequestBody(method: string, data: any): any;
|
|
17
|
+
protected buildRequestBody(method: string, data: any, sortList?: SortList): any;
|
|
18
|
+
/**
|
|
19
|
+
* OpenAPI 模式暂不支持 delete 操作
|
|
20
|
+
* @throws Error 当尝试调用 delete 时抛出错误
|
|
21
|
+
*/
|
|
22
|
+
delete(id: string | number): Promise<void>;
|
|
17
23
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbstractBaseModel } from './abstract-base-model';
|
|
2
|
+
import type { SortList } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* WebAPI 模型实现
|
|
4
5
|
* 处理 WebAPI 模式下的 URL 生成和请求体构建
|
|
@@ -11,5 +12,5 @@ export declare class WebApiModel extends AbstractBaseModel {
|
|
|
11
12
|
/**
|
|
12
13
|
* WebAPI 模式的请求体构建策略
|
|
13
14
|
*/
|
|
14
|
-
protected buildRequestBody(method: string, data: any): any;
|
|
15
|
+
protected buildRequestBody(method: string, data: any, sortList?: SortList): any;
|
|
15
16
|
}
|
|
@@ -13,6 +13,28 @@
|
|
|
13
13
|
* @description 支持的运行环境,用于区分不同的 API 端点
|
|
14
14
|
*/
|
|
15
15
|
export type Environment = 'online' | 'daily';
|
|
16
|
+
/**
|
|
17
|
+
* 排序方向枚举
|
|
18
|
+
* @description 定义数据排序的方向
|
|
19
|
+
*/
|
|
20
|
+
export declare enum SortOrder {
|
|
21
|
+
/** 升序 */
|
|
22
|
+
ASC = "asc",
|
|
23
|
+
/** 降序 */
|
|
24
|
+
DESC = "desc"
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 排序配置类型
|
|
28
|
+
* @description 定义排序规则的 key-value 格式,key 为字段名,value 为排序方向
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const sortList: SortList = [
|
|
32
|
+
* { "id": SortOrder.DESC },
|
|
33
|
+
* { "name": SortOrder.ASC }
|
|
34
|
+
* ];
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export type SortList = Record<string, SortOrder>[];
|
|
16
38
|
/**
|
|
17
39
|
* 列表查询参数接口
|
|
18
40
|
* @description 用于分页查询的通用参数接口
|
|
@@ -40,6 +62,35 @@ export interface ListResponse<T> {
|
|
|
40
62
|
/** 每页数量 */
|
|
41
63
|
pageSize: number;
|
|
42
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* 下拉选项接口
|
|
67
|
+
* @description 用于 Select 组件的选项数据格式
|
|
68
|
+
*/
|
|
69
|
+
export interface SelectOption {
|
|
70
|
+
/** 显示文本 */
|
|
71
|
+
label: string;
|
|
72
|
+
/** 选项值 */
|
|
73
|
+
value: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 获取下拉选项的参数接口
|
|
77
|
+
* @description 指定用于生成下拉选项的字段映射
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // 获取用户列表的下拉选项
|
|
81
|
+
* const options = await model.getSelectOptions({
|
|
82
|
+
* code: 'user_id', // 将 user_id 字段作为 value
|
|
83
|
+
* label: 'user_name' // 将 user_name 字段作为 label
|
|
84
|
+
* });
|
|
85
|
+
* // 返回: [{ label: '张三', value: 'user001' }, ...]
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export interface SelectOptionsParams {
|
|
89
|
+
/** 用作选项值的字段名 */
|
|
90
|
+
code: string;
|
|
91
|
+
/** 用作显示文本的字段名 */
|
|
92
|
+
label: string;
|
|
93
|
+
}
|
|
43
94
|
/**
|
|
44
95
|
* 单个模型配置接口
|
|
45
96
|
* @description 定义数据模型的基本配置信息
|
|
@@ -148,9 +199,10 @@ export interface BaseModelMethods {
|
|
|
148
199
|
* 获取数据列表
|
|
149
200
|
* @template T 返回数据的类型
|
|
150
201
|
* @param params 查询参数,包含分页等信息
|
|
202
|
+
* @param sortList 排序配置列表,可选参数
|
|
151
203
|
* @returns 返回分页数据
|
|
152
204
|
*/
|
|
153
|
-
getList<T = any>(params?: ListParams): Promise<ListResponse<T>>;
|
|
205
|
+
getList<T = any>(params?: ListParams, sortList?: SortList): Promise<ListResponse<T>>;
|
|
154
206
|
/**
|
|
155
207
|
* 获取单条数据
|
|
156
208
|
* @template T 返回数据的类型
|
|
@@ -177,6 +229,7 @@ export interface BaseModelMethods {
|
|
|
177
229
|
* 删除数据
|
|
178
230
|
* @param id 要删除的数据 ID
|
|
179
231
|
* @returns Promise<void>
|
|
232
|
+
* @throws Error OpenAPI 模式暂不支持此操作,仅 WebAPI 模式可用
|
|
180
233
|
*/
|
|
181
234
|
delete(id: string | number): Promise<void>;
|
|
182
235
|
/**
|
|
@@ -186,6 +239,22 @@ export interface BaseModelMethods {
|
|
|
186
239
|
* @description 获取当前应用下的所有数据集列表,主要用于 OpenAPI 模式
|
|
187
240
|
*/
|
|
188
241
|
getDatasetList<T = any>(): Promise<T[]>;
|
|
242
|
+
/**
|
|
243
|
+
* 获取下拉选项
|
|
244
|
+
* @param params 字段映射参数,指定用作 value 和 label 的字段名
|
|
245
|
+
* @returns 返回下拉选项数组
|
|
246
|
+
* @description 用于获取数据表的下拉选项数据,适用于 Select 组件(仅 WebAPI 模式支持)
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* // 获取用户下拉选项
|
|
250
|
+
* const options = await model.getSelectOptions({
|
|
251
|
+
* code: 'user_id',
|
|
252
|
+
* label: 'user_name'
|
|
253
|
+
* });
|
|
254
|
+
* // 返回: [{ label: '张三', value: 'user001' }, { label: '李四', value: 'user002' }]
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
getSelectOptions(params: SelectOptionsParams): Promise<SelectOption[]>;
|
|
189
258
|
}
|
|
190
259
|
/**
|
|
191
260
|
* 模型管理器接口
|