This repository was archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathpage.d.ts
More file actions
162 lines (138 loc) · 3.61 KB
/
page.d.ts
File metadata and controls
162 lines (138 loc) · 3.61 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
declare namespace tinyapp {
type OnShareAppMessageOptions = {
from: 'button';
target: Record<string, any>;
webViewUrl?: string;
} | {
from: 'menu';
webViewUrl?: string;
};
interface IOnShareAppMessageResult {
title: string;
desc?: string;
path: string;
content?: string;
imageUrl?: string;
bgImgUrl?: string;
success?(): void;
fail?(): void;
}
type IPageScrollEvent = [
{
readonly scrollTop: number;
readonly scrollHeight: number;
},
null,
null
] | {
readonly scrollTop: number;
readonly scrollHeight: number;
};
interface IPageEvents {
onBack?(): void;
onKeyboardHeight?(): void;
onOptionMenuClick?(): void;
onPopMenuClick?(): void;
onPullIntercept?(): void;
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh?(params: { from: 'manual' | 'code'; }): void;
onTitleClick?(): void;
/**
* 版本要求:基础库 1.11.0 或更高版本,若版本较低,建议做 兼容处理。
* 点击标签(tab)时触发。
*/
onTabItemTap?(item: { index: number; pagePath: string; text: string; }): void;
beforeTabItemTap?(): void;
}
interface IPageOptionsMethods extends Pick<
IPageEvents,
'onPullDownRefresh'
| 'onTitleClick'
| 'onOptionMenuClick'
| 'onPopMenuClick'
| 'onPullIntercept'
| 'onTabItemTap'
> {
/**
* 生命周期函数--监听页面加载
*
* @param query query 参数为 my.navigateTo 和 my.redirectTo 中传递的 query 对象。
*/
onLoad?(query: Query): void;
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady?(): void;
/**
* 生命周期函数--监听页面显示
*/
onShow?(): void;
/**
* 生命周期函数--监听页面隐藏
*/
onHide?(): void;
/**
* 生命周期函数--监听页面卸载
*/
onUnload?(): void;
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom?(): void;
/**
* 返回自定义分享信息
*/
onShareAppMessage?(options: OnShareAppMessageOptions): IOnShareAppMessageResult;
/**
* 页面滚动时触发
*
* @param event 滚动事件参数
*/
onPageScroll?(event: IPageScrollEvent): void;
}
type SetDataMethod<D> = (data: Partial<D>, callback?: () => void) => void;
interface ISpliceDataOperations {
[k: string]: [number, number, ...any[]];
}
type SpliceDataMethod = (operations: ISpliceDataOperations, callback?: () => void) => void;
type IPageInstance<D, M> = M & {
/**
* 页面数据。
*/
readonly data: D;
/**
* 将数据从逻辑层发送到视图层,同时改变对应的 this.data 的值
*/
setData: SetDataMethod<D>;
/**
* 同 setData,但是相比于 setData,在处理长列表的时候,其具有更高的性能
*/
$spliceData: SpliceDataMethod;
/**
* Page 路径,对应 app.json 中配置的路径值。
*/
readonly route: string;
/**
* 批量更新数据。
*/
$batchedUpdates: (fn: () => void) => void;
}
/**
* Page 实现的接口对象
*/
type PageOptions<D = Record<string, any>, M = Record<string, any>> = IPageOptionsMethods
& {
/**
* 初始数据或返回初始化数据的函数, 为对象时所有页面共享。
*/
data?: D;
/**
* 事件处理函数集合。
*/
events?: IPageEvents & ThisType<IPageInstance<D, M>>;
}
& M
& ThisType<IPageInstance<D, M>>;
}