zzz-pc-view 0.0.1

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.
Files changed (71) hide show
  1. package/package.json +29 -0
  2. package/src/api/org/list +96 -0
  3. package/src/api/org/type/list +18 -0
  4. package/src/api/own +3831 -0
  5. package/src/decorators/CurdKey/CurdApi.d.ts +221 -0
  6. package/src/decorators/CurdKey/RequestUtil.d.ts +55 -0
  7. package/src/decorators/CurdKey/index.d.ts +752 -0
  8. package/src/decorators/DeclareType.d.ts +35 -0
  9. package/src/decorators/Decorators.d.ts +5 -0
  10. package/src/decorators/FilterKey/index.d.ts +283 -0
  11. package/src/decorators/Loader/index.d.ts +179 -0
  12. package/src/decorators/NameKey/index.d.ts +68 -0
  13. package/src/decorators/PrimaryKey/index.d.ts +68 -0
  14. package/src/decorators/api.d.ts +21 -0
  15. package/src/decorators/decoratorStoreUtil.d.ts +68 -0
  16. package/src/decorators/index.d.ts +6 -0
  17. package/src/decorators/loadStore.d.ts +6 -0
  18. package/src/decorators/loadUtil.d.ts +25 -0
  19. package/src/decorators/util.d.ts +27 -0
  20. package/src/favicon.ico +0 -0
  21. package/src/index-decorators.d.ts +3 -0
  22. package/src/index.d.ts +10 -0
  23. package/src/index.es.js +10035 -0
  24. package/src/index.umd.js +2 -0
  25. package/src/pcViews/components/curd/CurdTableView.vue.d.ts +18 -0
  26. package/src/pcViews/components/curd/CurdView.vue.d.ts +22 -0
  27. package/src/pcViews/components/curd/CurdViewHandler.d.ts +1208 -0
  28. package/src/pcViews/components/curd/FilterView.vue.d.ts +19 -0
  29. package/src/pcViews/components/curd/FilterViewHandler.d.ts +6 -0
  30. package/src/pcViews/components/curd/index.d.ts +2 -0
  31. package/src/pcViews/components/forms/RadioButtonGroupView.vue.d.ts +19 -0
  32. package/src/pcViews/components/forms/SelectView.vue.d.ts +19 -0
  33. package/src/pcViews/components/forms/VModelView.vue.d.ts +20 -0
  34. package/src/pcViews/components/forms/index.d.ts +3 -0
  35. package/src/pcViews/components/index.d.ts +5 -0
  36. package/src/pcViews/components/layout/DataWrapperView.vue.d.ts +23 -0
  37. package/src/pcViews/components/layout/LayoutHeader.vue.d.ts +2 -0
  38. package/src/pcViews/components/layout/LayoutMainView.vue.d.ts +2 -0
  39. package/src/pcViews/components/layout/index.d.ts +2 -0
  40. package/src/pcViews/components/slots/VSlotView.vue.d.ts +20 -0
  41. package/src/pcViews/components/slots/index.d.ts +1 -0
  42. package/src/pcViews/components/utils.d.ts +33 -0
  43. package/src/pcViews/index.d.ts +1 -0
  44. package/src/utils/Date/ZDate.d.ts +557 -0
  45. package/src/utils/DeclareType.d.ts +39 -0
  46. package/src/utils/class/bind.d.ts +43 -0
  47. package/src/utils/class/combine.d.ts +109 -0
  48. package/src/utils/crypto/index.d.ts +44 -0
  49. package/src/utils/empty/index.d.ts +18 -0
  50. package/src/utils/httpRequest/HttpRequestError.d.ts +14 -0
  51. package/src/utils/httpRequest/httpRequestCreator.d.ts +61 -0
  52. package/src/utils/httpRequest/httpRequestUtil.d.ts +24 -0
  53. package/src/utils/httpRequest/index.d.ts +3 -0
  54. package/src/utils/index.d.ts +11 -0
  55. package/src/utils/math/toFixed.d.ts +11 -0
  56. package/src/utils/math/unitConvertor.d.ts +34 -0
  57. package/src/utils/mock/HttpResponse.d.ts +30 -0
  58. package/src/utils/mock/createDataTimes.d.ts +20 -0
  59. package/src/utils/mock/index.d.ts +2 -0
  60. package/src/utils/reduce/completeByDate.d.ts +51 -0
  61. package/src/utils/reduce/index.d.ts +9 -0
  62. package/src/utils/reduce/mappingBuilder.d.ts +69 -0
  63. package/src/utils/reduce/ratio.d.ts +104 -0
  64. package/src/utils/reduce/sort.d.ts +12 -0
  65. package/src/utils/reduce/sumByGroup.d.ts +53 -0
  66. package/src/utils/reduce/toGroup.d.ts +79 -0
  67. package/src/utils/reduce/tree.d.ts +570 -0
  68. package/src/utils/reduce/util.d.ts +14 -0
  69. package/src/utils/reduce/valueConvertor.d.ts +65 -0
  70. package/src/utils/reduce/verticalToHorizontal.d.ts +80 -0
  71. package/src/zzz-frame.css +7 -0
@@ -0,0 +1,35 @@
1
+ import { WithPrototype } from '../utils';
2
+ /**
3
+ * 定义一个接口,用于描述基本属性配置。
4
+ * 该接口包含一个属性:
5
+ * - `propertyKey`:属性键,类型为字符串或符号。
6
+ */
7
+ export interface BasePropertyConfig {
8
+ propertyKey: string | symbol;
9
+ }
10
+ /**
11
+ * 定义一个类型别名,用于描述带有原型的类型。
12
+ * 该类型别名是`WithPrototype`类型的类型。
13
+ */
14
+ export type TypeWithPrototype = typeof WithPrototype;
15
+ /**
16
+ * 定义一个类型别名,用于描述带有原型的类型,但不包括`new`操作符。
17
+ * 该类型别名通过`Omit`类型工具从`TypeWithPrototype`类型中移除`new`属性。
18
+ * @type {TypeWithPrototypeWithoutNew}
19
+ * @description 这个类型别名通常用于在不允许使用`new`操作符的上下文中使用带有原型的类型。
20
+ */
21
+ export type TypeWithPrototypeWithoutNew = Omit<TypeWithPrototype, 'new'>;
22
+ /**
23
+ * 定义一个类型别名,用于描述组件属性。
24
+ * 该类型别名是一个记录类型,键为属性键,值为未知类型。
25
+ */
26
+ export type ComponentProps = Record<PropertyKey, unknown>;
27
+ /**
28
+ * 定义一个类型别名,用于描述事件处理函数映射。
29
+ * 该类型别名是一个记录类型,键为字符串,值为函数类型,函数接受任意数量的未知类型参数,并且不返回任何值。
30
+ */
31
+ export type EventHandlerMap = Record<string, (...args: unknown[]) => void>;
32
+ /**
33
+ * 导出一个空对象,用于确保该模块有一个默认导出。
34
+ */
35
+ export {};
@@ -0,0 +1,5 @@
1
+ export * as NameKey from './NameKey';
2
+ export * as PrimaryKey from './PrimaryKey';
3
+ export * as Loader from './Loader';
4
+ export * as FilterKey from './FilterKey';
5
+ export * as CurdKey from './CurdKey';
@@ -0,0 +1,283 @@
1
+ import { Reactive } from 'vue';
2
+ import { CombineClass, CombineInstanceType } from '../../utils';
3
+ import { BasePropertyConfig, ComponentProps, EventHandlerMap, TypeWithPrototype } from '../DeclareType';
4
+ import { ConfigsCreator } from '../util';
5
+ /**
6
+ * 定义一个枚举,用于表示过滤器的位置。
7
+ */
8
+ export declare enum PositionEnum {
9
+ /**
10
+ * 顶部位置。
11
+ */
12
+ TOP = 0,
13
+ /**
14
+ * 右侧位置。
15
+ */
16
+ RIGHT = 1,
17
+ /**
18
+ * 底部位置。
19
+ */
20
+ BOTTOM = 2,
21
+ /**
22
+ * 左侧位置。
23
+ */
24
+ LEFT = 3
25
+ }
26
+ /**
27
+ * 定义一个接口,用于描述映射的配置。
28
+ * 该接口是一个泛型接口,接受两个类型参数 `Q` 和 `T`,分别表示查询对象的类型和目标对象的类型。
29
+ * 该接口包含两个属性,分别是目标对象和获取查询的函数。
30
+ * @template Q - 查询对象的类型。
31
+ * @template T - 目标对象的类型。
32
+ */
33
+ interface Mapping<Q extends object = object, T extends TypeWithPrototype | void = void> {
34
+ /**
35
+ * 映射的目标。
36
+ */
37
+ Target: T;
38
+ /**
39
+ * 获取查询的函数。
40
+ * 该函数是一个可选的函数,接受一个查询对象作为参数,并返回任何类型的值。
41
+ * @param query - 查询对象。
42
+ * @returns 返回任何类型的值。
43
+ */
44
+ getQuery?(query: Q): unknown;
45
+ }
46
+ /**
47
+ * 定义一个接口,用于描述过滤器的响应参数。
48
+ * 该接口是一个泛型接口,接受两个类型参数 `Q` 和 `T`,分别表示查询对象的类型和目标对象的类型。
49
+ * 该接口包含多个可选属性,用于配置过滤器的行为和外观。
50
+ * @template Q - 查询对象的类型。
51
+ * @template T - 目标对象的类型。
52
+ */
53
+ export interface ResponseParam<Q extends object = object, T extends TypeWithPrototype | void = void> {
54
+ /**
55
+ * 过滤器的标签,用于显示在用户界面上。
56
+ */
57
+ label?: string;
58
+ /**
59
+ * 过滤器的顺序号,用于确定过滤器在用户界面上的显示顺序。
60
+ */
61
+ orderNo?: number;
62
+ /**
63
+ * 一个布尔值,指示过滤器是否应该显示在用户界面上。
64
+ */
65
+ show?: boolean;
66
+ /**
67
+ * 过滤器在用户界面上的位置。
68
+ */
69
+ position?: PositionEnum;
70
+ /**
71
+ * 定义一个可选的验证器函数,用于验证过滤器的值。
72
+ * 该函数可以返回一个 Promise,该 Promise 解析为字符串或 Error 对象,或者返回 void。
73
+ * 如果返回的是字符串或 Error 对象,则表示验证失败,否则表示验证成功。
74
+ * @returns 返回一个 Promise,该 Promise 解析为字符串或 Error 对象,或者返回 void。
75
+ */
76
+ validator?(): string | Error | Promise<string | Error> | void;
77
+ /**
78
+ * 过滤器组件的属性。
79
+ */
80
+ itemProps?: ComponentProps;
81
+ /**
82
+ * 过滤器组件的类型。
83
+ */
84
+ component?: unknown;
85
+ /**
86
+ * 过滤器组件的属性。
87
+ */
88
+ componentProps?: ComponentProps;
89
+ /**
90
+ * 过滤器组件的事件处理程序。
91
+ */
92
+ componentOn?: EventHandlerMap;
93
+ /**
94
+ * 一个映射对象,用于将查询对象映射到目标对象。
95
+ */
96
+ mapping?: T extends TypeWithPrototype ? Mapping<Q, T> : void;
97
+ /**
98
+ * 一个函数,用于设置过滤器的默认值。
99
+ * 该函数接受两个参数,分别是查询对象和选项数组。
100
+ * 如果目标对象是 `CombineClass` 类型,则选项数组是 `CombineInstanceType<T>[]` 类型,否则为 `void` 类型。
101
+ * @param query - 查询对象。
102
+ * @param options - 选项数组。
103
+ */
104
+ setDefaultValue?(query: Q, options: T extends CombineClass ? CombineInstanceType<T>[] : void): void;
105
+ }
106
+ /**
107
+ * 定义一个接口,用于描述装饰器的参数。
108
+ * 该接口是一个泛型接口,接受两个类型参数 `Q` 和 `T`,分别表示查询对象的类型和目标对象的类型。
109
+ * 该接口包含一个方法,该方法返回一个 `ResponseParam` 类型的对象。
110
+ * @template Q - 查询对象的类型。
111
+ * @template T - 目标对象的类型。
112
+ */
113
+ export interface Param<Q extends object = object, T extends TypeWithPrototype | void = void> {
114
+ /**
115
+ * 一个方法,返回一个 `ResponseParam` 类型的对象。
116
+ * 该方法没有参数。
117
+ * @returns 返回一个 `ResponseParam` 类型的对象。
118
+ */
119
+ (this: FilterHandler<Q>): ResponseParam<Q, T>;
120
+ }
121
+ /**
122
+ * 定义一个接口,用于描述配置对象。
123
+ * 该接口继承自 `BasePropertyConfig` 和 `Param` 接口。
124
+ */
125
+ export interface Config extends BasePropertyConfig {
126
+ creator: Param;
127
+ }
128
+ /**
129
+ * 定义一个接口,用于描述视图处理程序的配置。
130
+ * 该接口继承自 `BasePropertyConfig` 和 `Param` 接口的返回类型。
131
+ */
132
+ interface HandlerConfig extends BasePropertyConfig, ReturnType<Param> {
133
+ }
134
+ /**
135
+ * 定义一个抽象类 `FilterHandler`,用于处理视图的配置和加载选项。
136
+ * 该类继承自 `ConfigsCreator`,并使用泛型 `Q` 表示查询对象的类型。
137
+ * @template Q - 查询对象的类型。
138
+ */
139
+ export declare abstract class FilterHandler<Q extends object> extends ConfigsCreator {
140
+ readonly filterOption?: {
141
+ autoLoadOptions?: boolean;
142
+ } | undefined;
143
+ /**
144
+ * 定义一个属性 `FilterTarget`,用于存储查询对象的原型。
145
+ */
146
+ protected readonly FilterTarget: TypeWithPrototype;
147
+ /**
148
+ * 定义一个只读属性 `query`,用于存储查询对象的响应式副本。
149
+ */
150
+ readonly query: Reactive<Q>;
151
+ /**
152
+ * 使用 `shallowRef` 创建一个浅引用,用于存储过滤器配置的数组。
153
+ * `shallowRef` 用于创建一个浅层的响应式引用,它不会递归地将对象转换为响应式。
154
+ */
155
+ protected readonly filterConfigsRef: import('vue').ShallowRef<HandlerConfig[] | undefined, HandlerConfig[] | undefined>;
156
+ /**
157
+ * 定义一个只读的计算属性 `filterConfigMapComputed`,用于计算过滤器配置的映射。
158
+ * 该计算属性基于 `filterConfigsRef` 的值,将过滤器配置数组转换为一个以 `propertyKey` 为键的对象。
159
+ * 如果 `filterConfigsRef` 没有值,则返回一个空对象。
160
+ * @returns 返回一个以 `propertyKey` 为键的对象,或者一个空对象。
161
+ */
162
+ protected readonly filterConfigMapComputed: import('vue').ComputedRef<Record<PropertyKey, HandlerConfig>>;
163
+ /**
164
+ * 获取过滤器配置的映射。
165
+ * 该方法返回 `filterConfigMapComputed` 的值,即过滤器配置的映射。
166
+ * @returns 返回一个以 `propertyKey` 为键的对象,或者一个空对象。
167
+ */
168
+ get filterConfigMap(): Record<PropertyKey, HandlerConfig>;
169
+ /**
170
+ * 定义一个只读的计算属性 `displayFilterConfigMapComputed`,用于计算过滤器配置的位置映射。
171
+ * 该计算属性基于 `filterConfigsRef` 的值,将过滤器配置数组转换为一个以 `PositionEnum` 为键的对象。
172
+ * 如果 `filterConfigsRef` 没有值,则返回一个空对象。
173
+ * @returns 返回一个以 `PositionEnum` 为键的对象,或者一个空对象。
174
+ */
175
+ private readonly displayFilterConfigMapComputed;
176
+ /**
177
+ * 获取过滤器配置的位置映射。
178
+ * 该方法返回 `displayFilterConfigMapComputed` 的值,即过滤器配置的位置映射。
179
+ * @returns 返回一个以 `PositionEnum` 为键的对象,或者一个空对象。
180
+ */
181
+ get displayFilterConfigMap(): Record<PositionEnum, HandlerConfig[]>;
182
+ /**
183
+ * 定义一个计算属性 `positionKeysComputed`,用于获取过滤器配置的位置键。
184
+ * 该计算属性基于 `displayFilterConfigMap` 的键,将其转换为 `PositionEnum` 数组。
185
+ * @returns 返回一个 `PositionEnum` 数组。
186
+ */
187
+ private readonly positionKeysComputed;
188
+ /**
189
+ * 获取过滤器配置的位置键。
190
+ * 该方法返回 `positionKeysComputed` 的值,即过滤器配置的位置键。
191
+ * @returns 返回一个 `PositionEnum` 数组。
192
+ */
193
+ get positionKeys(): PositionEnum[];
194
+ /**
195
+ * 当查询验证成功时调用的抽象方法。
196
+ * 子类必须实现此方法以定义在查询验证成功时应执行的操作。
197
+ */
198
+ protected abstract onValidateQuerySuccess(): void;
199
+ /**
200
+ * 当查询验证失败时调用的抽象方法。
201
+ * 子类必须实现此方法以定义在查询验证失败时应执行的操作。
202
+ * @param error - 验证失败时抛出的错误对象。
203
+ */
204
+ protected abstract onValidateQueryFail(error: Error): void;
205
+ /**
206
+ * 定义一个受保护的异步方法 `validateQuery`,用于验证查询。
207
+ * 该方法遍历过滤器配置数组,对每个配置执行验证器函数。
208
+ * 如果验证器函数返回一个值,则抛出该值作为错误。
209
+ * @returns 返回一个 Promise,该 Promise 在所有验证完成后解析。
210
+ */
211
+ protected validateQuery(): Promise<void>;
212
+ /**
213
+ * 定义一个受保护的方法 `search`,用于执行搜索操作。
214
+ * 该方法首先调用 `validateQuery` 方法来验证查询。
215
+ * 如果验证成功,则调用 `onValidateQuerySuccess` 方法。
216
+ * 如果验证失败,则调用 `onValidateQueryFail` 方法,并传递错误对象。
217
+ */
218
+ protected search(): void;
219
+ /**
220
+ * 获取查询加载状态存储对象。
221
+ * 该方法返回全局的加载状态存储对象 `loadStore`。
222
+ * @returns 返回全局的加载状态存储对象 `loadStore`。
223
+ */
224
+ get queryLoadStore(): import('..').LoadUtilResponse;
225
+ /**
226
+ * 获取查询加载状态。
227
+ * 该方法返回全局的加载状态存储对象 `loadStore` 中的 `loadStatus` 属性。
228
+ * @returns 返回全局的加载状态存储对象 `loadStore` 中的 `loadStatus` 属性。
229
+ */
230
+ get queryLoadStatus(): boolean;
231
+ /**
232
+ * 定义一个私有方法 `loadOption`,用于加载选项。
233
+ * 该方法接受一个 `ResponseParam` 类型的参数 `config`,并根据配置加载选项。
234
+ * @param config - 包含映射信息的过滤器配置。
235
+ * @returns 返回一个 Promise,该 Promise 在选项加载完成后解析。
236
+ */
237
+ private loadOption;
238
+ /**
239
+ * 定义一个公共方法 `loadOptionByProp`,用于根据属性名加载选项。
240
+ * 该方法接受一个字符串参数 `prop`,表示属性名,并根据该属性名加载选项。
241
+ * @param prop - 要加载选项的属性名。
242
+ * @returns 返回一个 Promise,该 Promise 在选项加载完成后解析。
243
+ */
244
+ loadOptionByProp(prop: string): Promise<void>;
245
+ /**
246
+ * 定义一个公共方法 `processFilterConfigs`,用于处理过滤器配置。
247
+ * 该方法遍历过滤器配置数组,根据配置加载选项或设置默认值。
248
+ * @returns 返回一个 Promise,该 Promise 在所有配置处理完成后解析。
249
+ */
250
+ processFilterConfigs(): Promise<void>;
251
+ /**
252
+ * 构造函数,用于初始化过滤器处理程序。
253
+ * @param query - 查询对象,用于初始化过滤器处理程序。
254
+ */
255
+ constructor(query: Q, filterOption?: {
256
+ autoLoadOptions?: boolean;
257
+ } | undefined);
258
+ }
259
+ /**
260
+ * 定义一个装饰器,用于将配置对象存储在目标对象的原型上。
261
+ * 该装饰器接受一个参数对象,其中包含要装饰的类。
262
+ * 当装饰器应用于一个属性时,它会将配置对象存储在目标对象的原型上。
263
+ * 配置对象包含目标对象、属性键以及从参数对象继承的所有属性描述符。
264
+ * @param {Param<Q, T>} param - 装饰器的参数对象,包含要装饰的类。
265
+ * @returns {PropertyDecorator} 返回一个属性装饰器函数。
266
+ */
267
+ export declare const decorator: <Q extends object, T extends TypeWithPrototype | void>(param: Param<Q, T>) => ((target: Q, propertyKey: string | symbol) => void);
268
+ /**
269
+ * 根据对象的原型获取所有配置。
270
+ * 该函数首先调用 `getConfigByPrototypeAndKey` 函数并传递对象的原型和键作为参数。
271
+ * 然后将返回的结果转换为 `Config` 数组或 `undefined`。
272
+ * @param {object} target - 要获取配置的对象的原型。
273
+ * @returns {undefined | Config[]} 返回配置数组,如果没有找到配置,则返回 undefined。
274
+ */
275
+ export declare const getConfigsByPrototype: (target: object) => undefined | Config[];
276
+ /**
277
+ * 根据类获取所有配置。
278
+ * 该函数首先获取类的原型,然后调用 `getConfigsByPrototype` 函数并传递类的原型作为参数。
279
+ * @param {ClassType} Class - 要获取配置的类。
280
+ * @returns {undefined | Config[]} 返回配置数组,如果没有找到配置,则返回 undefined。
281
+ */
282
+ export declare const getConfigsByClass: (Class: TypeWithPrototype) => Config[] | undefined;
283
+ export {};
@@ -0,0 +1,179 @@
1
+ import { ComputedRef, Ref } from 'vue';
2
+ import { CombineInstanceType, KeyMatch, KeyValType } from '../../utils';
3
+ import { HttpRequestPromise } from '../../utils/httpRequest';
4
+ import { TypeWithPrototype } from '../DeclareType';
5
+ /**
6
+ * Loader 的存储接口,包含一个列表引用和一个计算属性
7
+ * @template T 类的类型
8
+ */
9
+ export interface Store<T extends TypeWithPrototype = TypeWithPrototype> {
10
+ listRef: Ref<CombineInstanceType<T>[]>;
11
+ mapComputed: ComputedRef<Record<KeyValType, CombineInstanceType<T>>>;
12
+ }
13
+ /**
14
+ * 定义一个唯一的 Symbol 作为 Loader 存储的键名
15
+ */
16
+ declare const storeKey: unique symbol;
17
+ /**
18
+ * Loader 存储类型的接口,包含一个存储对象
19
+ * @template T 类的类型
20
+ */
21
+ interface StoreType<T extends TypeWithPrototype = TypeWithPrototype> {
22
+ [storeKey]: Store<T>;
23
+ }
24
+ /**
25
+ * API 列表的接口,包含一个获取列表的方法
26
+ * @template T 列表项的类型
27
+ */
28
+ export interface ApiList<T extends TypeWithPrototype = TypeWithPrototype> {
29
+ getList(query?: any): HttpRequestPromise<CombineInstanceType<T>[]>;
30
+ }
31
+ /**
32
+ * Loader 的参数接口,包含 API 列表、全局标志、子键和加载完成的回调函数
33
+ */
34
+ export interface Param<T extends TypeWithPrototype = TypeWithPrototype> {
35
+ api: ApiList<T>;
36
+ query?: any;
37
+ global?: boolean;
38
+ childrenKey?: KeyMatch<CombineInstanceType<T>, undefined | CombineInstanceType<T>[]>;
39
+ onLoaded?: (list: CombineInstanceType<T>[]) => CombineInstanceType<T>[];
40
+ }
41
+ /**
42
+ * Loader 类类型的类型别名,包含类、存储类型和原型类型
43
+ * @template T 类的类型
44
+ */
45
+ export type LoaderClassType<T extends TypeWithPrototype = TypeWithPrototype> = T & StoreType<T> & TypeWithPrototype;
46
+ /**
47
+ * Loader 的配置类,实现了 Param 接口
48
+ * @template T 类的类型
49
+ */
50
+ declare class LoaderConfig<T extends TypeWithPrototype = TypeWithPrototype> implements Param<T> {
51
+ readonly target: LoaderClassType<T>;
52
+ api: ApiList<T>;
53
+ query: any;
54
+ global: boolean;
55
+ childrenKey?: KeyMatch<CombineInstanceType<T>, undefined | CombineInstanceType<T>[]>;
56
+ onLoaded?: (list: CombineInstanceType<T>[]) => CombineInstanceType<T>[];
57
+ /**
58
+ * 构造函数
59
+ * @param target - 目标类
60
+ * @param param - 配置参数
61
+ */
62
+ constructor(target: LoaderClassType<T>, param: Param<T>);
63
+ }
64
+ /**
65
+ * 定义一个类型别名 `Config`,用于表示 `LoaderConfig` 类型,该类型接受一个泛型参数 `T`,`T` 必须是一个类类型。
66
+ * 这个类型别名主要用于简化代码,使得在使用 `LoaderConfig` 类型时可以直接使用 `Config`,而不需要每次都指定泛型参数。
67
+ * @template T 一个类类型,用于指定 `LoaderConfig` 类型的泛型参数。
68
+ */
69
+ export type Config<T extends TypeWithPrototype = TypeWithPrototype> = LoaderConfig<T>;
70
+ /**
71
+ * 定义一个装饰器函数 `decorator`,用于装饰类。
72
+ * 该装饰器接受一个参数 `param`,类型为 `Param`,并返回一个类装饰器。
73
+ * @param param - 一个 `Param` 类型的对象,包含 API 列表、全局标志、子键和加载完成的回调函数。
74
+ * @returns 返回一个类装饰器,该装饰器将配置信息存储在类的原型上。
75
+ *
76
+ * @example
77
+ @Loader.decorator({
78
+ api: {
79
+ getList: () => api<MyClass[]>({
80
+ url: '/myclass',
81
+ method: 'GET',
82
+ }),
83
+ },
84
+ // global: true, // 是否为全局配置(只加载一次),默认值为 false
85
+ // onLoaded: (list) => list.map(item => new MyClass(item)), // 可选参数,用于数据返回后格式化数据
86
+ })
87
+ class MyClass {
88
+ @PrimaryKey.decorator()
89
+ declare id: KeyValType
90
+
91
+ @NameKey.decorator()
92
+ declare name: string
93
+ }
94
+ */
95
+ export declare const decorator: <T extends TypeWithPrototype>(param: Param<T>) => ((target: T) => T | void);
96
+ /**
97
+ * 加载全局配置中的所有列表数据。
98
+ *
99
+ * 该函数遍历全局配置数组 `globalConfigs`,并为每个配置调用 `setList` 函数,
100
+ * 该函数会异步获取列表数据并将其设置到配置的目标类上。
101
+ *
102
+ * @returns {Promise<void>} 返回一个 Promise,当所有配置的列表数据都加载完成时,Promise 会被 resolve。
103
+ */
104
+ export declare const loadGlobal: () => Promise<void>;
105
+ /**
106
+ * 加载数据的函数。
107
+ *
108
+ * 该函数接受一个目标类作为参数,根据配置信息加载数据。
109
+ * 如果配置为全局加载,则直接返回存储在目标类中的数据;否则,调用API获取数据并设置到目标类中。
110
+ *
111
+ * @template T 目标类的类型,必须是一个类类型。
112
+ * @param {T} target 目标类的实例。
113
+ * @returns {Promise<CombineInstanceType<T>[]>} 返回一个Promise,当数据加载完成时,Promise会被resolve,返回加载的数据。
114
+ *
115
+ * @throws {Error} 如果找不到与目标类关联的配置信息,则抛出错误。
116
+ *
117
+ * @example
118
+ * @Loader.decorator({
119
+ api: {
120
+ getList: () => api<MyClass[]>({
121
+ url: '/myclass',
122
+ method: 'GET',
123
+ }),
124
+ },
125
+ // onLoaded: (list) => list.map(item => new MyClass(item)), // 可选参数,用于数据返回后格式化数据
126
+ })
127
+ class MyClass {
128
+ @PrimaryKey.decorator()
129
+ declare id: KeyValType
130
+
131
+ @NameKey.decorator()
132
+ declare name: string
133
+ }
134
+
135
+ Loader.loadData(MyClass).then(dataList => {
136
+ console.log(dataList)
137
+ })
138
+ */
139
+ export declare const loadData: <T extends TypeWithPrototype>(target: T, query?: any) => Promise<CombineInstanceType<T>[]>;
140
+ /**
141
+ * 获取目标类的存储对象。
142
+ *
143
+ * 该函数接受一个目标类作为参数,并尝试从该类中获取存储对象。
144
+ * 如果目标类是一个 `LoaderClassType`,则返回其存储对象;否则返回 `undefined`。
145
+ *
146
+ * @template T 目标类的类型,必须是一个类类型。
147
+ * @param {T} target 目标类的实例。
148
+ * @returns {undefined | Store<T>} 返回目标类的存储对象,如果目标类不是 `LoaderClassType`,则返回 `undefined`。
149
+ *
150
+ * @example
151
+ @Loader.decorator({
152
+ api: {
153
+ getList: () => api<MyClass[]>({
154
+ url: '/myclass',
155
+ method: 'GET',
156
+ }),
157
+ },
158
+ global: true, // 是否为全局配置(只加载一次),默认值为 false
159
+ // onLoaded: (list) => list.map(item => new MyClass(item)), // 可选参数,用于数据返回后格式化数据
160
+ })
161
+ class MyClass {
162
+ @PrimaryKey.decorator()
163
+ declare id: KeyValType
164
+
165
+ @NameKey.decorator()
166
+ declare name: string
167
+ }
168
+
169
+ Loader.getData(MyClass)
170
+ const store = Loader.getData(MyClass)
171
+
172
+ // 输出
173
+ {
174
+ listRef: shallowRef<MyClass[]>([]),
175
+ mapComputed: computed<Record<KeyValType, MyClass>>(() => {})
176
+ }
177
+ */
178
+ export declare const getData: <T extends TypeWithPrototype = typeof import('../../utils').WithPrototype>(target: T) => undefined | Store<T>;
179
+ export {};
@@ -0,0 +1,68 @@
1
+ import { ClassType, KeyMatch, KeyValType } from './../../utils';
2
+ /**
3
+ * 定义一个泛型接口,用于描述主键配置。
4
+ * 该接口接受一个泛型类型参数 `T`,表示目标对象的类型。
5
+ * 接口包含一个属性 `propertyKey`,表示主键的属性名。
6
+ * `propertyKey` 的类型是 `KeyMatch<T, KeyValType>`,表示它必须是 `T` 类型的键,并且键值类型是 `KeyValType`。
7
+ * @template T - 目标对象的类型。
8
+ */
9
+ export interface Config<T extends object> {
10
+ /**
11
+ * 主键的属性名。
12
+ * 该属性是一个泛型类型 `KeyMatch<T, KeyValType>`,表示它必须是 `T` 类型的键,并且键值类型是 `KeyValType`。
13
+ */
14
+ propertyKey: KeyMatch<T, KeyValType>;
15
+ }
16
+ /**
17
+ * 创建一个装饰器函数,用于为类的属性添加元数据。
18
+ * 该装饰器函数接受一个泛型类型参数 `T`,表示目标对象的类型。
19
+ * 装饰器函数返回一个函数,该函数接受两个参数:`target` 和 `propertyKey`。
20
+ * `target` 是目标对象的原型,`propertyKey` 是要装饰的属性名。
21
+ * 装饰器函数将属性名存储在目标对象原型的元数据中。
22
+ * @template T - 目标对象的类型。
23
+ * @returns 返回一个装饰器函数,该函数接受 `target` 和 `propertyKey` 作为参数。
24
+ *
25
+ * @example
26
+ class Test {
27
+ @NameKey.decorator()
28
+ name: string
29
+ }
30
+ */
31
+ export declare const decorator: <T extends object>() => ((target: T, propertyKey: KeyMatch<T, string>) => void);
32
+ /**
33
+ * 根据目标对象的原型获取 NameKey 的配置。
34
+ * 该函数接受一个泛型类型参数 `T`,表示目标对象的类型。
35
+ * 函数返回一个 NameKey 配置对象,或者 `undefined`。
36
+ * @template T - 目标对象的类型。
37
+ * @param target - 目标对象的原型。
38
+ * @returns 返回 NameKey 配置对象,或者 `undefined`。
39
+ *
40
+ * @example
41
+ * class Test {
42
+ * @NameKey.decorator()
43
+ * name: string
44
+ * }
45
+ *
46
+ * const config = NameKey.getByPrototype(Test.prototype)
47
+ * // config 可能是 { propertyKey: 'name' },或者 undefined
48
+ */
49
+ export declare const getByPrototype: <T extends object>(target: T) => undefined | Config<T>;
50
+ /**
51
+ * 根据类获取 NameKey 的配置
52
+ * @param Class - 目标类
53
+ * @returns 返回 NameKey 的配置,如果不存在则返回 undefined
54
+ *
55
+ * @example
56
+ class Test {
57
+ @NameKey.decorator()
58
+ name: string
59
+ }
60
+
61
+ NameKey.getByClass(Test)
62
+
63
+ // 输出
64
+ {
65
+ propertyKey: 'name'
66
+ }
67
+ */
68
+ export declare const getByClass: (Class: ClassType) => Config<any> | undefined;
@@ -0,0 +1,68 @@
1
+ import { ClassType, KeyMatch, KeyValType } from './../../utils';
2
+ /**
3
+ * 定义一个接口,用于描述主键配置。
4
+ * 该接口是一个泛型接口,接受一个类型参数 `T`,表示目标对象的类型。
5
+ * 接口包含一个属性 `propertyKey`,表示主键的属性名。
6
+ * `propertyKey` 的类型是 `KeyMatch<T, KeyValType>`,表示它必须是 `T` 类型的键,并且键值类型是 `KeyValType`。
7
+ * @template T - 目标对象的类型。
8
+ */
9
+ export interface Config<T extends object> {
10
+ /**
11
+ * 主键的属性名。
12
+ * 该属性是一个泛型类型 `KeyMatch<T, KeyValType>`,表示它必须是 `T` 类型的键,并且键值类型是 `KeyValType`。
13
+ */
14
+ propertyKey: KeyMatch<T, KeyValType>;
15
+ }
16
+ /**
17
+ * 创建一个装饰器函数,用于为类的属性添加元数据。
18
+ * 该装饰器函数接受一个泛型类型参数 `T`,表示目标对象的类型。
19
+ * 装饰器函数返回一个函数,该函数接受两个参数:`target` 和 `propertyKey`。
20
+ * `target` 是目标对象的原型,`propertyKey` 是要装饰的属性名。
21
+ * 装饰器函数将属性名存储在目标对象原型的元数据中。
22
+ * @template T - 目标对象的类型。
23
+ * @returns 返回一个装饰器函数,该函数接受 `target` 和 `propertyKey` 作为参数。
24
+ *
25
+ * @example
26
+ class Test {
27
+ @PrimaryKey.decorator()
28
+ id: number
29
+ }
30
+ */
31
+ export declare const decorator: <T extends object>() => ((target: T, propertyKey: KeyMatch<T, KeyValType>) => void);
32
+ /**
33
+ * 根据目标对象的原型获取主键配置。
34
+ * 该函数接受一个泛型类型参数 `T`,表示目标对象的类型。
35
+ * 函数返回一个主键配置对象,或者 `undefined`。
36
+ * @template T - 目标对象的类型。
37
+ * @param target - 目标对象的原型。
38
+ * @returns 返回主键配置对象,或者 `undefined`。
39
+ *
40
+ * @example
41
+ * class Test {
42
+ * @PrimaryKey.decorator()
43
+ * id: number
44
+ * }
45
+ *
46
+ * const config = PrimaryKey.getByPrototype(Test.prototype)
47
+ * // config 可能是 { propertyKey: 'id' },或者 undefined
48
+ */
49
+ export declare const getByPrototype: <T extends object>(target: T) => undefined | Config<T>;
50
+ /**
51
+ * 根据类获取主键配置
52
+ * @param Class - 目标类
53
+ * @returns 返回主键配置,如果不存在则返回 undefined
54
+ *
55
+ * @example
56
+ class Test {
57
+ @PrimaryKey.decorator()
58
+ id: number
59
+ }
60
+
61
+ PrimaryKey.getByPrototype(Test)
62
+
63
+ // 输出
64
+ {
65
+ propertyKey: 'id'
66
+ }
67
+ */
68
+ export declare const getByClass: <T extends ClassType>(Class: T) => undefined | Config<InstanceType<T>>;
@@ -0,0 +1,21 @@
1
+ import { httpRequest } from '../utils';
2
+ /**
3
+ * 导出一个变量 `api`,它是一个 `HttpRequestLoader` 类型的实例。
4
+ * 这个实例用于发送 HTTP 请求。
5
+ */
6
+ export declare let api: httpRequest.HttpRequestLoader;
7
+ /**
8
+ * 导出一个函数 `setApi`,用于设置 `api` 变量的值。
9
+ * 这个函数接受可变数量的参数,这些参数将被传递给 `httpRequest.create` 函数。
10
+ * @param args - 传递给 `httpRequest.create` 函数的参数。
11
+ */
12
+ export declare const setApi: (option: {
13
+ axiosOptions: import('axios').CreateAxiosDefaults;
14
+ errorDataCode: httpRequest.HttpRequestError["code"];
15
+ requestIntercept?(requestConfig: import('axios').InternalAxiosRequestConfig): import('axios').InternalAxiosRequestConfig | Promise<import('axios').InternalAxiosRequestConfig>;
16
+ errorHandler?(error: httpRequest.HttpRequestError): Promise<httpRequest.HttpRequestError>;
17
+ dataCodeProp?: string | number;
18
+ dataSuccessCodeRanges?: ([number, number] | number | string)[];
19
+ dataMsgProp?: string | number;
20
+ dataDataProp?: string | number;
21
+ }) => void;