zzz-pc-view 0.0.28 → 0.0.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zzz-pc-view",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "main": "src/index.umd.js",
5
5
  "module": "src/index.es.js",
6
6
  "types": "src/index.d.ts",
@@ -24,6 +24,8 @@
24
24
  "element-plus": "^2.9.1",
25
25
  "color-hash": "^2.0.2",
26
26
  "animate.css": "^4.1.1",
27
- "mitt": "^3.0.1"
27
+ "mitt": "^3.0.1",
28
+ "@types/mockjs": "^1.0.10",
29
+ "mockjs": "^1.1.0"
28
30
  }
29
31
  }
@@ -7,6 +7,7 @@ import { Config as NameKeyConfig } from './../NameKey';
7
7
  import { RequestUtilResponse } from '../useRequestUtil';
8
8
  import { ZUtils } from '../../index-decorators';
9
9
  export * from './CurdApi';
10
+ export * from './useCurdMock';
10
11
  /**
11
12
  * 基础参数接口,用于定义通用的参数属性。
12
13
  */
@@ -0,0 +1,82 @@
1
+ import { ZUtils } from '../../index-decorators';
2
+ /**
3
+ * 定义一个 Mock 监听器接口,用于配置 Mock 请求的相关信息
4
+ */
5
+ export interface MockListener {
6
+ method?: 'GET' | 'get' | 'POST' | 'post' | 'PUT' | 'put' | 'DELETE' | 'delete';
7
+ template?: any | ((params: any) => any);
8
+ }
9
+ /**
10
+ * 定义 Mock 分页配置接口,继承自 MockListener 接口,用于配置分页请求和响应的属性
11
+ * @extends MockListener
12
+ */
13
+ export interface MockPagination extends MockListener {
14
+ /**
15
+ * 分页请求参数的属性名配置
16
+ */
17
+ pageRequestProps: {
18
+ /**
19
+ * 请求中表示当前页码的属性名
20
+ */
21
+ page: string;
22
+ /**
23
+ * 请求中表示每页数据条数的属性名
24
+ */
25
+ size: string;
26
+ };
27
+ /**
28
+ * 分页响应数据的属性名配置
29
+ */
30
+ pageResponseProps: {
31
+ /**
32
+ * 响应中表示数据总条数的属性名
33
+ */
34
+ total: string;
35
+ /**
36
+ * 响应中表示数据列表的属性名
37
+ */
38
+ list: string;
39
+ };
40
+ }
41
+ /**
42
+ * 定义一个用于过滤列表数据的函数类型接口
43
+ * @param list - 待过滤的列表数据,类型为泛型 T 的数组
44
+ * @param query - 可选的查询参数,类型为任意类型
45
+ * @returns 返回过滤后的列表数据,类型为泛型 T 的数组
46
+ */
47
+ export interface MockListFilter<T> {
48
+ (list: T[], query?: any): T[];
49
+ }
50
+ /**
51
+ * 创建一个用于模拟 CRUD 操作的钩子函数
52
+ * @param option - 配置选项
53
+ * @param option.basePath - 基础路径
54
+ * @param option.Target - 目标类
55
+ * @param option.list - 初始列表数据
56
+ * @param option.listFilter - 列表过滤器,可选
57
+ * @param option.listener - 监听器配置
58
+ * @param option.listener.list - 列表请求监听器,可选
59
+ * @param option.listener.page - 分页请求监听器,可选
60
+ * @param option.listener.create - 创建请求监听器,可选
61
+ * @param option.listener.detail - 详情请求监听器,可选
62
+ * @param option.listener.update - 更新请求监听器,可选
63
+ * @param option.listener.delete - 删除请求监听器,可选
64
+ * @returns 包含列表和映射对象的对象
65
+ */
66
+ export declare const useCurdMock: <T extends ZUtils.ClassType>(option: {
67
+ basePath: string;
68
+ Target: T;
69
+ list: InstanceType<T>[];
70
+ listFilter?: MockListFilter<InstanceType<T>>;
71
+ listener: {
72
+ list?: MockListener;
73
+ page?: MockPagination;
74
+ create?: MockListener;
75
+ detail?: MockListener;
76
+ update?: MockListener;
77
+ delete?: MockListener;
78
+ };
79
+ }) => {
80
+ readonly list: InstanceType<T>[];
81
+ readonly map: Record<PropertyKey, InstanceType<T>>;
82
+ };