common.d.ts
2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* 公共命名空间声明
*/
declare namespace CommonTypes {
/**
* 定义一个基本的响应对象接口
*/
type IResponseBase = {
/**
* 状态码
*/
code?: number
/**
* 响应信息
*/
message?: string | string[]
/**
* 请求接口路径
*/
url?: string
error?: any
/**
* 时间戳
*/
timestamp?: number
}
type IPage = {
/**
* 总条数
*/
total: number
/**
* 页码
*/
pageIndex: number
/**
* 当前页条数
*/
pageSize: number
}
/**
* 扩展分页对象接口,包括总条数
*/
type IPagenation = Partial<IPage>
/**
/**
* 响应数据接口,继承自分页对象接口,包含业务数据
*/
interface IResData<T = any> extends IPagenation {
/**
* 业务数据
*/
data?: T
}
/**
* 全局响应体接口,继承自分页对象、响应基本对象和响应数据接口
*/
type IResponse<T> = IResData<T> & IResponseBase
/**
* 扩展分页对象接口,用于传入查询参数,包含附加属性
*/
// interface IPageIn extends IPageBase {
// [key: string]: any
// }
type IPageIn = Omit<IPagenation, 'total'> & TObj
/**
* 定义一个基本的查询对象接口
*/
interface IQueryBase {
/**
* 跳过数量
*/
skip?: number
/**
* 获取数量
*/
take?: number
}
/**
* 定义一个响应体生成函数类型
*
* @param result - 响应数据
* @param msg - 消息
* @param code - 状态码
* @param url - 路径
* @returns 返回给前端的响应体
*/
type TBodyResponse = (result: IResData, message?: string | string[], code?: number, error?: any, url?: string) => IResponse<IResData<any>>
type Optional<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>
type PartialOne<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
type TObj = { [key: string]: any }
interface IDeviceId {
device_id: number
}
interface IId {
id: number
}
interface ITime {
created_at: Date | string
updated_at: Date | string
}
interface ISn {
sn: string
}
interface IUser extends IDeviceId, ISn {
user: string
mobile: string
merchant_name: string
}
}