@tarojs/taro 3.6.6-alpha.1 → 3.6.6-alpha.3
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 +6 -3
- package/types/api/base/index.d.ts +2 -2
- package/types/api/base/weapp/app-event.d.ts +18 -18
- package/types/api/network/request.d.ts +18 -15
- package/types/api/taro.extend.d.ts +200 -0
- package/types/{taro.hooks.d.ts → api/taro.hooks.d.ts} +4 -4
- package/types/compile/compiler.d.ts +1 -1
- package/types/compile/config/project.d.ts +1 -1
- package/types/global.d.ts +8 -8
- package/types/index.d.ts +5 -7
- package/types/taro.api.d.ts +4 -1
- package/types/taro.component.d.ts +1 -1
- package/types/taro.extend.d.ts +0 -126
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/taro",
|
|
3
|
-
"version": "3.6.6-alpha.
|
|
3
|
+
"version": "3.6.6-alpha.3",
|
|
4
4
|
"description": "Taro framework",
|
|
5
5
|
"homepage": "https://github.com/nervjs/taro/tree/master/packages/taro#readme",
|
|
6
6
|
"main": "index.js",
|
|
@@ -21,8 +21,11 @@
|
|
|
21
21
|
"author": "O2Team",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@tarojs/api": "3.6.6-alpha.
|
|
25
|
-
"@tarojs/runtime": "3.6.6-alpha.
|
|
24
|
+
"@tarojs/api": "3.6.6-alpha.3",
|
|
25
|
+
"@tarojs/runtime": "3.6.6-alpha.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@tarojs/helper": "3.6.6-alpha.3"
|
|
26
29
|
},
|
|
27
30
|
"peerDependenciesMeta": {
|
|
28
31
|
"@types/react": {
|
|
@@ -3,7 +3,7 @@ import Taro from '../../index'
|
|
|
3
3
|
declare module '../../index' {
|
|
4
4
|
interface TaroStatic {
|
|
5
5
|
/** 判断小程序的 API,回调,参数,组件等是否在当前版本可用。
|
|
6
|
-
* @supported weapp, tt
|
|
6
|
+
* @supported weapp, tt, h5
|
|
7
7
|
* @example
|
|
8
8
|
* ```tsx
|
|
9
9
|
* Taro.canIUse('openBluetoothAdapter')
|
|
@@ -36,7 +36,7 @@ declare module '../../index' {
|
|
|
36
36
|
): boolean
|
|
37
37
|
|
|
38
38
|
/** 判断能否使用 WebP 格式
|
|
39
|
-
*
|
|
39
|
+
*
|
|
40
40
|
* > 在小程序平台中仅在 android 和 devtools 设备时可用
|
|
41
41
|
* @supported global
|
|
42
42
|
*/
|
|
@@ -18,7 +18,7 @@ declare module '../../../index' {
|
|
|
18
18
|
/** 小程序错误事件的回调函数 */
|
|
19
19
|
type Callback = (
|
|
20
20
|
/** 错误信息,包含堆栈 */
|
|
21
|
-
error: string,
|
|
21
|
+
error: string | ErrorEvent | Error,
|
|
22
22
|
) => void
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -113,13 +113,13 @@ declare module '../../../index' {
|
|
|
113
113
|
*
|
|
114
114
|
* **注意**
|
|
115
115
|
* - 所有的 unhandledRejection 都可以被这一监听捕获,但只有 Error 类型的才会在小程序后台触发报警。
|
|
116
|
-
* @supported weapp, tt
|
|
116
|
+
* @supported weapp, tt, h5
|
|
117
117
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html
|
|
118
118
|
*/
|
|
119
119
|
onUnhandledRejection<T = any>(callback: onUnhandledRejection.Callback<T>): void
|
|
120
120
|
|
|
121
121
|
/** 监听系统主题改变事件。该事件与 [`App.onThemeChange`](https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html#onThemeChange-Object-object) 的回调时机一致。
|
|
122
|
-
* @supported weapp
|
|
122
|
+
* @supported weapp, h5
|
|
123
123
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onThemeChange.html
|
|
124
124
|
*/
|
|
125
125
|
onThemeChange(callback: onThemeChange.Callback): void
|
|
@@ -131,13 +131,13 @@ declare module '../../../index' {
|
|
|
131
131
|
* - 开发者可以在回调中进行页面重定向,但必须在回调中**同步**处理,异步处理(例如 `setTimeout` 异步执行)无效。
|
|
132
132
|
* - 若开发者没有调用 [Taro.onPageNotFound](/docs/apis/base/weapp/app-event/onPageNotFound) 绑定监听,也没有声明 `App.onPageNotFound`,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。
|
|
133
133
|
* - 如果回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再第二次回调。
|
|
134
|
-
* @supported weapp,
|
|
134
|
+
* @supported weapp, tt, h5
|
|
135
135
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onPageNotFound.html
|
|
136
136
|
*/
|
|
137
137
|
onPageNotFound(callback: onPageNotFound.Callback): void
|
|
138
138
|
|
|
139
139
|
/** 监听小程序错误事件。如脚本错误或 API 调用报错等。该事件与 [`App.onError`](https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html#onerrorstring-error) 的回调时机与参数一致。
|
|
140
|
-
* @supported weapp, tt
|
|
140
|
+
* @supported weapp, tt, h5
|
|
141
141
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onError.html
|
|
142
142
|
*/
|
|
143
143
|
onError(callback: onError.Callback): void
|
|
@@ -178,16 +178,16 @@ declare module '../../../index' {
|
|
|
178
178
|
* **注意**
|
|
179
179
|
*
|
|
180
180
|
* 部分版本在无`referrerInfo`的时候会返回 `undefined`,建议使用 `options.referrerInfo && options.referrerInfo.appId` 进行判断。
|
|
181
|
-
* @supported weapp,
|
|
181
|
+
* @supported weapp, tt, h5
|
|
182
182
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onAppShow.html
|
|
183
183
|
*/
|
|
184
184
|
onAppShow(
|
|
185
185
|
/** 小程序切前台事件的回调函数 */
|
|
186
|
-
callback: (
|
|
186
|
+
callback: (res: onAppShow.CallbackResult) => void,
|
|
187
187
|
): void
|
|
188
188
|
|
|
189
189
|
/** 监听小程序切后台事件。该事件与 [`App.onHide`](https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html#onhide) 的回调时机一致。
|
|
190
|
-
* @supported weapp,
|
|
190
|
+
* @supported weapp, tt, h5
|
|
191
191
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onAppHide.html
|
|
192
192
|
*/
|
|
193
193
|
onAppHide(
|
|
@@ -196,34 +196,34 @@ declare module '../../../index' {
|
|
|
196
196
|
): void
|
|
197
197
|
|
|
198
198
|
/** 取消监听未处理的 Promise 拒绝事件
|
|
199
|
-
* @supported weapp, tt
|
|
199
|
+
* @supported weapp, tt, h5
|
|
200
200
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.offUnhandledRejection.html
|
|
201
201
|
*/
|
|
202
202
|
offUnhandledRejection<T = any>(callback: onUnhandledRejection.Callback<T>): void
|
|
203
203
|
|
|
204
204
|
/** 取消监听系统主题改变事件
|
|
205
|
-
* @supported weapp
|
|
205
|
+
* @supported weapp, h5
|
|
206
206
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.offThemeChange.html
|
|
207
207
|
*/
|
|
208
208
|
offThemeChange(callback: onThemeChange.Callback): void
|
|
209
209
|
|
|
210
210
|
/** 取消监听小程序要打开的页面不存在事件
|
|
211
|
-
* @supported weapp, tt
|
|
211
|
+
* @supported weapp, tt, h5
|
|
212
212
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.offPageNotFound.html
|
|
213
213
|
*/
|
|
214
214
|
offPageNotFound(
|
|
215
215
|
/** 小程序要打开的页面不存在事件的回调函数 */
|
|
216
|
-
callback:
|
|
216
|
+
callback: onPageNotFound.Callback,
|
|
217
217
|
): void
|
|
218
218
|
|
|
219
219
|
/** 取消监听音频播放错误事件
|
|
220
|
-
* @supported weapp, tt
|
|
220
|
+
* @supported weapp, tt, h5
|
|
221
221
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.offError.html
|
|
222
222
|
*/
|
|
223
223
|
|
|
224
224
|
offError(
|
|
225
225
|
/** 音频播放错误事件的回调函数 */
|
|
226
|
-
callback:
|
|
226
|
+
callback: onError.Callback,
|
|
227
227
|
): void
|
|
228
228
|
|
|
229
229
|
/** 取消监听音频中断结束事件
|
|
@@ -245,21 +245,21 @@ declare module '../../../index' {
|
|
|
245
245
|
): void
|
|
246
246
|
|
|
247
247
|
/** 取消监听小程序切前台事件
|
|
248
|
-
* @supported weapp,
|
|
248
|
+
* @supported weapp, tt, h5
|
|
249
249
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.offAppShow.html
|
|
250
250
|
*/
|
|
251
251
|
offAppShow(
|
|
252
252
|
/** 小程序切前台事件的回调函数 */
|
|
253
|
-
callback: (res:
|
|
253
|
+
callback: (res: onAppShow.CallbackResult) => void,
|
|
254
254
|
): void
|
|
255
255
|
|
|
256
256
|
/** 取消监听小程序切后台事件
|
|
257
|
-
* @supported weapp,
|
|
257
|
+
* @supported weapp, tt, h5
|
|
258
258
|
* @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.offAppHide.html
|
|
259
259
|
*/
|
|
260
260
|
offAppHide(
|
|
261
261
|
/** 小程序切后台事件的回调函数 */
|
|
262
|
-
callback: (res:
|
|
262
|
+
callback: (res: onAppHide.CallbackResult) => void,
|
|
263
263
|
): void
|
|
264
264
|
}
|
|
265
265
|
}
|
|
@@ -60,58 +60,61 @@ declare module '../../index' {
|
|
|
60
60
|
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
61
61
|
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
62
62
|
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
63
|
-
/**
|
|
63
|
+
/** 设置是否使用 jsonp 方式获取数据
|
|
64
64
|
* @default false
|
|
65
65
|
* @supported h5
|
|
66
66
|
*/
|
|
67
|
-
jsonp?: boolean
|
|
68
|
-
/** 设置
|
|
69
|
-
* @default false
|
|
67
|
+
jsonp?: boolean | string
|
|
68
|
+
/** 设置 jsonp 请求 url 是否需要被缓存
|
|
70
69
|
* @supported h5
|
|
71
70
|
*/
|
|
72
|
-
jsonpCache?:
|
|
73
|
-
/**
|
|
71
|
+
jsonpCache?: RequestCache
|
|
72
|
+
/** 设置是否允许跨域请求
|
|
74
73
|
* @default "same-origin"
|
|
75
74
|
* @supported h5
|
|
76
75
|
*/
|
|
77
76
|
mode?: keyof CorsMode
|
|
78
|
-
/**
|
|
77
|
+
/** 设置是否携带 Cookie
|
|
79
78
|
* @default "omit"
|
|
80
79
|
* @supported h5
|
|
81
80
|
*/
|
|
82
81
|
credentials?: keyof Credentials
|
|
83
|
-
/**
|
|
82
|
+
/** 设置缓存模式
|
|
84
83
|
* @default "default"
|
|
85
84
|
* @supported h5
|
|
86
85
|
*/
|
|
87
86
|
cache?: keyof Cache
|
|
88
|
-
/**
|
|
87
|
+
/** 设置请求重试次数
|
|
89
88
|
* @default 2
|
|
90
89
|
* @supported h5
|
|
91
90
|
*/
|
|
92
91
|
retryTimes?: number
|
|
93
|
-
/**
|
|
92
|
+
/** 设置请求的兜底接口
|
|
94
93
|
* @supported h5
|
|
95
94
|
*/
|
|
96
95
|
backup?: string | string[]
|
|
97
|
-
/**
|
|
96
|
+
/** 设置请求中止信号
|
|
97
|
+
* @supported h5
|
|
98
|
+
*/
|
|
99
|
+
signal?: AbortSignal
|
|
100
|
+
/** 设置请求响应的数据校验函数,若返回 false,则请求兜底接口,若无兜底接口,则报请求失败
|
|
98
101
|
* @supported h5
|
|
99
102
|
*/
|
|
100
103
|
dataCheck?(): boolean
|
|
101
|
-
/**
|
|
104
|
+
/** 设置请求是否使用缓存
|
|
102
105
|
* @default false
|
|
103
106
|
* @supported h5
|
|
104
107
|
*/
|
|
105
108
|
useStore?: boolean
|
|
106
|
-
/**
|
|
109
|
+
/** 设置请求缓存校验的 key
|
|
107
110
|
* @supported h5
|
|
108
111
|
*/
|
|
109
112
|
storeCheckKey?: string
|
|
110
|
-
/**
|
|
113
|
+
/** 设置请求缓存签名
|
|
111
114
|
* @supported h5
|
|
112
115
|
*/
|
|
113
116
|
storeSign?: string
|
|
114
|
-
/**
|
|
117
|
+
/** 设置请求校验函数,一般不需要设置
|
|
115
118
|
* @supported h5
|
|
116
119
|
*/
|
|
117
120
|
storeCheck?(): boolean
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import Taro from '../index'
|
|
4
|
+
|
|
5
|
+
declare module '../index' {
|
|
6
|
+
namespace getAppInfo {
|
|
7
|
+
/** 应用信息 */
|
|
8
|
+
interface AppInfo {
|
|
9
|
+
platform: string
|
|
10
|
+
taroVersion: string
|
|
11
|
+
designWidth: number | ((size?: string | number) => number)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
namespace getCurrentInstance {
|
|
16
|
+
interface Current {
|
|
17
|
+
app: AppInstance | null
|
|
18
|
+
router: RouterInfo | null
|
|
19
|
+
page: PageInstance | null
|
|
20
|
+
onReady: string
|
|
21
|
+
onHide: string
|
|
22
|
+
onShow: string
|
|
23
|
+
preloadData?: Record<any, any>
|
|
24
|
+
/**
|
|
25
|
+
* RN 私有对象navigationRef,用于使用底层接口控制路由
|
|
26
|
+
*/
|
|
27
|
+
rnNavigationRef?: React.RefObject<any>
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
namespace setGlobalDataPlugin {
|
|
32
|
+
/** Vue3 插件,用于设置 `getApp()` 中的全局变量 */
|
|
33
|
+
interface Plugin {
|
|
34
|
+
install (app: any, data: any): void
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @ignore */
|
|
39
|
+
interface TARO_ENV_TYPE {
|
|
40
|
+
[TaroGeneral.ENV_TYPE.WEAPP]: TaroGeneral.ENV_TYPE.WEAPP
|
|
41
|
+
[TaroGeneral.ENV_TYPE.WEB]: TaroGeneral.ENV_TYPE.WEB
|
|
42
|
+
[TaroGeneral.ENV_TYPE.RN]: TaroGeneral.ENV_TYPE.RN
|
|
43
|
+
[TaroGeneral.ENV_TYPE.SWAN]: TaroGeneral.ENV_TYPE.SWAN
|
|
44
|
+
[TaroGeneral.ENV_TYPE.ALIPAY]: TaroGeneral.ENV_TYPE.ALIPAY
|
|
45
|
+
[TaroGeneral.ENV_TYPE.TT]: TaroGeneral.ENV_TYPE.TT
|
|
46
|
+
[TaroGeneral.ENV_TYPE.QQ]: TaroGeneral.ENV_TYPE.QQ
|
|
47
|
+
[TaroGeneral.ENV_TYPE.JD]: TaroGeneral.ENV_TYPE.JD
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
namespace interceptorify {
|
|
51
|
+
type promiseifyApi<T, R> = (requestParams: T) => Promise<R>
|
|
52
|
+
interface InterceptorifyChain<T, R> {
|
|
53
|
+
requestParams: T
|
|
54
|
+
proceed: promiseifyApi<T, R>
|
|
55
|
+
}
|
|
56
|
+
type InterceptorifyInterceptor<T, R> = (chain: InterceptorifyChain<T, R>) => Promise<R>
|
|
57
|
+
interface Interceptorify<T, R> {
|
|
58
|
+
request(requestParams: T): Promise<R>
|
|
59
|
+
addInterceptor( interceptor: InterceptorifyInterceptor<T, R>): void
|
|
60
|
+
cleanInterceptors(): void
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface TaroStatic {
|
|
65
|
+
/** @ignore */
|
|
66
|
+
Events: {
|
|
67
|
+
new (): TaroGeneral.Events
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 事件中心
|
|
71
|
+
* @supported global
|
|
72
|
+
*/
|
|
73
|
+
eventCenter: TaroGeneral.Events
|
|
74
|
+
|
|
75
|
+
/** @ignore */
|
|
76
|
+
ENV_TYPE: TARO_ENV_TYPE
|
|
77
|
+
|
|
78
|
+
/** 获取环境变量
|
|
79
|
+
* @supported global
|
|
80
|
+
*/
|
|
81
|
+
getEnv(): TaroGeneral.ENV_TYPE
|
|
82
|
+
|
|
83
|
+
/** 尺寸转换
|
|
84
|
+
* @supported global
|
|
85
|
+
*/
|
|
86
|
+
pxTransform(size: number, designWidth?: number): string
|
|
87
|
+
|
|
88
|
+
/** 尺寸转换初始化
|
|
89
|
+
* @supported global
|
|
90
|
+
*/
|
|
91
|
+
initPxTransform(config: {
|
|
92
|
+
baseFontSize?: number
|
|
93
|
+
deviceRatio?: TaroGeneral.TDeviceRatio
|
|
94
|
+
designWidth?: number | ((size?: string | number) => number)
|
|
95
|
+
targetUnit?: string
|
|
96
|
+
unitPrecision?: number
|
|
97
|
+
}): void
|
|
98
|
+
|
|
99
|
+
/** 小程序获取和 Taro 相关的 App 信息
|
|
100
|
+
* @supported weapp, alipay, jd, qq, swan, tt, h5
|
|
101
|
+
*/
|
|
102
|
+
getAppInfo(): getAppInfo.AppInfo
|
|
103
|
+
|
|
104
|
+
/** 小程序引用插件 JS 接口
|
|
105
|
+
* @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
|
|
106
|
+
*/
|
|
107
|
+
requirePlugin(pluginName: string): any
|
|
108
|
+
|
|
109
|
+
/** 获取当前页面实例
|
|
110
|
+
* @supported global
|
|
111
|
+
*/
|
|
112
|
+
getCurrentInstance(): getCurrentInstance.Current
|
|
113
|
+
|
|
114
|
+
/** @ignore */
|
|
115
|
+
Current: getCurrentInstance.Current
|
|
116
|
+
|
|
117
|
+
/** Vue3 插件,用于设置 `getApp()` 中的全局变量
|
|
118
|
+
* @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
|
|
119
|
+
* @example
|
|
120
|
+
* ```js
|
|
121
|
+
* // 使用插件
|
|
122
|
+
* const App = createApp(...)
|
|
123
|
+
* App.use(setGlobalDataPlugin, {
|
|
124
|
+
* xxx: 999
|
|
125
|
+
* })
|
|
126
|
+
* // 获取全局变量
|
|
127
|
+
* Taro.getApp().xxx
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
setGlobalDataPlugin: setGlobalDataPlugin.Plugin
|
|
131
|
+
|
|
132
|
+
/** 获取自定义 TabBar 对应的 React 或 Vue 组件实例
|
|
133
|
+
* @supported weapp
|
|
134
|
+
* @param page 小程序页面对象,可以通过 Taro.getCurrentInstance().page 获取
|
|
135
|
+
*/
|
|
136
|
+
getTabBar<T>(page: getCurrentInstance.Current['page']): T | undefined
|
|
137
|
+
|
|
138
|
+
/** 获取当前页面渲染引擎类型
|
|
139
|
+
* @supported weapp
|
|
140
|
+
*/
|
|
141
|
+
getRenderer(): 'webview' | 'skyline'
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 包裹 promiseify api 的洋葱圈模型
|
|
145
|
+
* @supported global
|
|
146
|
+
* @param promiseifyApi
|
|
147
|
+
* @example
|
|
148
|
+
* ```tsx
|
|
149
|
+
* // 创建实例
|
|
150
|
+
* const modalInterceptorify = interceptorify(taro.showModal)
|
|
151
|
+
* // 添加拦截器
|
|
152
|
+
* modalInterceptorify.addInterceptor(async function (chain) {
|
|
153
|
+
* const res = await chain.proceed({
|
|
154
|
+
* ...chain.requestParams,
|
|
155
|
+
* title: 'interceptor1'
|
|
156
|
+
* })
|
|
157
|
+
* return res
|
|
158
|
+
* })
|
|
159
|
+
* modalInterceptorify.addInterceptor(async function (chain) {
|
|
160
|
+
* const res = await chain.proceed({
|
|
161
|
+
* ...chain.requestParams,
|
|
162
|
+
* content: 'interceptor2'
|
|
163
|
+
* })
|
|
164
|
+
* return res
|
|
165
|
+
* })
|
|
166
|
+
* // 使用
|
|
167
|
+
* modalInterceptorify.request({})
|
|
168
|
+
* ```
|
|
169
|
+
* @example
|
|
170
|
+
* ```tsx
|
|
171
|
+
* // 创建实例
|
|
172
|
+
* const fetchDataInterceptorify = interceptorify(taro.request)
|
|
173
|
+
* // 添加拦截器
|
|
174
|
+
* fetchDataInterceptorify.addInterceptor(async function (chain) {
|
|
175
|
+
* taro.showLoading({
|
|
176
|
+
* title: 'Loading...'
|
|
177
|
+
* })
|
|
178
|
+
* const res = await chain.proceed(chain.requestParams)
|
|
179
|
+
* taro.hideLoading()
|
|
180
|
+
* return res
|
|
181
|
+
* })
|
|
182
|
+
* fetchDataInterceptorify.addInterceptor(async function (chain) {
|
|
183
|
+
* const params = chain.requestParams
|
|
184
|
+
* const res = await chain.proceed({
|
|
185
|
+
* url: 'http://httpbin.org' + params.url,
|
|
186
|
+
* })
|
|
187
|
+
* return res.data
|
|
188
|
+
* })
|
|
189
|
+
* // 使用
|
|
190
|
+
* fetchDataInterceptorify.request({
|
|
191
|
+
* url: '/ip'
|
|
192
|
+
* }).then((res) => {
|
|
193
|
+
* // log my ip
|
|
194
|
+
* console.log(res.origin)
|
|
195
|
+
* })
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
interceptorify<T, R>(promiseifyApi: interceptorify.promiseifyApi<T, R>): interceptorify.Interceptorify<T, R>
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Taro from '
|
|
1
|
+
import Taro from '../index'
|
|
2
2
|
|
|
3
|
-
declare module '
|
|
3
|
+
declare module '../index' {
|
|
4
4
|
interface TaroStatic {
|
|
5
5
|
/**
|
|
6
6
|
* 页面展示时的回调。
|
|
@@ -46,7 +46,7 @@ declare module './index' {
|
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* 当前是 tab 页时,tab 被点击时的回调。
|
|
49
|
-
* @supported weapp, rn
|
|
49
|
+
* @supported weapp, h5, rn
|
|
50
50
|
*/
|
|
51
51
|
useTabItemTap(callback: (payload: TabItemTapObject) => void): void
|
|
52
52
|
|
|
@@ -85,7 +85,7 @@ declare module './index' {
|
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* 小程序有未处理的 Promise reject 时触发。也可以使用 Taro.onUnhandledRejection 绑定监听。
|
|
88
|
-
* @supported weapp, alipay
|
|
88
|
+
* @supported weapp, alipay, h5
|
|
89
89
|
*/
|
|
90
90
|
useUnhandledRejection(callback: (error: { reason: Error, promise: Promise<Error> }) => void): void
|
|
91
91
|
|
|
@@ -24,7 +24,7 @@ export interface IProjectBaseConfig {
|
|
|
24
24
|
port?: number
|
|
25
25
|
projectName?: string
|
|
26
26
|
date?: string
|
|
27
|
-
designWidth?: number | ((size
|
|
27
|
+
designWidth?: number | ((size?: string | number) => number)
|
|
28
28
|
deviceRatio?: TaroGeneral.TDeviceRatio
|
|
29
29
|
watcher?: any[]
|
|
30
30
|
sourceRoot?: string
|
package/types/global.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare namespace TaroGeneral {
|
|
|
6
6
|
type EventCallback = (
|
|
7
7
|
/** 触发事件参数 */
|
|
8
8
|
...args: any
|
|
9
|
-
|
|
9
|
+
) => void
|
|
10
10
|
/** 通用错误 */
|
|
11
11
|
interface CallbackResult {
|
|
12
12
|
/** 错误信息 */
|
|
@@ -35,7 +35,7 @@ declare namespace TaroGeneral {
|
|
|
35
35
|
/** 阻止事件冒泡到父元素,阻止任何父事件处理程序被执行 */
|
|
36
36
|
stopPropagation: () => void
|
|
37
37
|
}
|
|
38
|
-
interface currentTarget extends Target {}
|
|
38
|
+
interface currentTarget extends Target { }
|
|
39
39
|
interface Target {
|
|
40
40
|
/** 事件源组件的id */
|
|
41
41
|
id: string
|
|
@@ -378,33 +378,33 @@ declare namespace TaroGeneral {
|
|
|
378
378
|
*/
|
|
379
379
|
13024
|
|
380
380
|
}
|
|
381
|
-
|
|
381
|
+
type EventName = string | symbol
|
|
382
382
|
// Events
|
|
383
383
|
class Events {
|
|
384
384
|
/**
|
|
385
385
|
* 监听一个事件,接受参数
|
|
386
386
|
*/
|
|
387
|
-
on(eventName:
|
|
387
|
+
on (eventName: EventName, listener: (...args: any[]) => void): this
|
|
388
388
|
|
|
389
389
|
/**
|
|
390
390
|
* 添加一个事件监听,并在事件触发完成之后移除Callbacks链
|
|
391
391
|
*/
|
|
392
|
-
once(eventName:
|
|
392
|
+
once (eventName: EventName, listener: (...args: any[]) => void): this
|
|
393
393
|
|
|
394
394
|
/**
|
|
395
395
|
* 取消监听一个事件
|
|
396
396
|
*/
|
|
397
|
-
off(eventName:
|
|
397
|
+
off (eventName: EventName, listener?: (...args: any[]) => void): this
|
|
398
398
|
|
|
399
399
|
/**
|
|
400
400
|
* 取消监听的所有事件
|
|
401
401
|
*/
|
|
402
|
-
off(): this
|
|
402
|
+
off (): this
|
|
403
403
|
|
|
404
404
|
/**
|
|
405
405
|
* 触发一个事件,传参
|
|
406
406
|
*/
|
|
407
|
-
trigger(eventName:
|
|
407
|
+
trigger (eventName: EventName, ...args: any[]): this
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
// ENV_TYPE
|
package/types/index.d.ts
CHANGED
|
@@ -108,13 +108,13 @@
|
|
|
108
108
|
* │ │ └── interaction.d.ts 界面 -> 交互 API
|
|
109
109
|
* │ ├── worker
|
|
110
110
|
* │ │ └── index.d.ts Worker API
|
|
111
|
-
* │
|
|
112
|
-
* │
|
|
111
|
+
* │ ├── wxml
|
|
112
|
+
* │ │ └── index.d.ts WXML API
|
|
113
|
+
* │ ├── taro.extend.d.ts Taro 扩展 API 类型定义
|
|
114
|
+
* │ └── taro.hooks.d.ts Taro Hooks 类型定义
|
|
113
115
|
* ├── index.d.ts 此文件
|
|
114
116
|
* ├── taro.component.d.ts Taro Component 类型定义
|
|
115
|
-
* ├── taro.config.d.ts
|
|
116
|
-
* ├── taro.extend.d.ts Taro 扩展 API 类型定义
|
|
117
|
-
* ├── taro.hooks.d.ts Taro Hooks 类型定义
|
|
117
|
+
* ├── taro.config.d.ts Taro 小程序 App 与 Window 设置类型定义
|
|
118
118
|
* └── taro.lifecycle.d.ts Taro 生命周期类型定义
|
|
119
119
|
*/
|
|
120
120
|
|
|
@@ -123,8 +123,6 @@
|
|
|
123
123
|
/// <reference path="taro.api.d.ts" />
|
|
124
124
|
/// <reference path="taro.component.d.ts" />
|
|
125
125
|
/// <reference path="taro.config.d.ts" />
|
|
126
|
-
/// <reference path="taro.extend.d.ts" />
|
|
127
|
-
/// <reference path="taro.hooks.d.ts" />
|
|
128
126
|
/// <reference path="taro.lifecycle.d.ts" />
|
|
129
127
|
|
|
130
128
|
/// <reference types="@tarojs/plugin-platform-alipay/types/shims-alipay" />
|
package/types/taro.api.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
*
|
|
3
3
|
* 微信端能力
|
|
4
4
|
* original code from: https://github.com/wx-minapp/minapp-wx/blob/master/typing/wx.d.ts
|
|
5
|
-
*
|
|
5
|
+
* Licensed under MIT license: https://github.com/qiu8310/minapp/issues/69
|
|
6
6
|
* thanks for the great work by @qiu8310 👍👍👍
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
@@ -110,3 +110,6 @@
|
|
|
110
110
|
/// <reference path="api/alipay/index.d.ts" />
|
|
111
111
|
/// <reference path="api/qq/index.d.ts" />
|
|
112
112
|
/// <reference path="api/swan/index.d.ts" />
|
|
113
|
+
|
|
114
|
+
/// <reference path="api/taro.extend.d.ts" />
|
|
115
|
+
/// <reference path="api/taro.hooks.d.ts" />
|
package/types/taro.extend.d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
import Taro from './index'
|
|
4
|
-
|
|
5
|
-
declare module './index' {
|
|
6
|
-
type MessageType = 'info' | 'success' | 'error' | 'warning'
|
|
7
|
-
|
|
8
|
-
interface AtMessageOptions {
|
|
9
|
-
message: string
|
|
10
|
-
type?: MessageType
|
|
11
|
-
duration?: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface AppInfo {
|
|
15
|
-
platform: string,
|
|
16
|
-
taroVersion: string
|
|
17
|
-
designWidth: number
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface RequestParams<T=any> extends request.Option<T, any> {
|
|
21
|
-
[propName: string]: any
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface Current {
|
|
25
|
-
app: AppInstance | null
|
|
26
|
-
router: RouterInfo | null
|
|
27
|
-
page: PageInstance | null
|
|
28
|
-
onReady: string
|
|
29
|
-
onHide: string
|
|
30
|
-
onShow: string
|
|
31
|
-
preloadData?: Record<any, any>
|
|
32
|
-
/**
|
|
33
|
-
* RN 私有对象navigationRef,用于使用底层接口控制路由
|
|
34
|
-
*/
|
|
35
|
-
rnNavigationRef?: React.RefObject<any>
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
interface SetGlobalDataPlugin {
|
|
39
|
-
install (app: any, data: any): void
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface TARO_ENV_TYPE {
|
|
43
|
-
[TaroGeneral.ENV_TYPE.WEAPP]: TaroGeneral.ENV_TYPE.WEAPP
|
|
44
|
-
[TaroGeneral.ENV_TYPE.WEB]: TaroGeneral.ENV_TYPE.WEB
|
|
45
|
-
[TaroGeneral.ENV_TYPE.RN]: TaroGeneral.ENV_TYPE.RN
|
|
46
|
-
[TaroGeneral.ENV_TYPE.SWAN]: TaroGeneral.ENV_TYPE.SWAN
|
|
47
|
-
[TaroGeneral.ENV_TYPE.ALIPAY]: TaroGeneral.ENV_TYPE.ALIPAY
|
|
48
|
-
[TaroGeneral.ENV_TYPE.TT]: TaroGeneral.ENV_TYPE.TT
|
|
49
|
-
[TaroGeneral.ENV_TYPE.QQ]: TaroGeneral.ENV_TYPE.QQ
|
|
50
|
-
[TaroGeneral.ENV_TYPE.JD]: TaroGeneral.ENV_TYPE.JD
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
interface TaroStatic {
|
|
54
|
-
Events: {
|
|
55
|
-
new (): TaroGeneral.Events
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** 事件中心
|
|
59
|
-
* @supported global
|
|
60
|
-
*/
|
|
61
|
-
eventCenter: TaroGeneral.Events
|
|
62
|
-
|
|
63
|
-
ENV_TYPE: TARO_ENV_TYPE
|
|
64
|
-
|
|
65
|
-
/** 获取环境变量
|
|
66
|
-
* @supported global
|
|
67
|
-
*/
|
|
68
|
-
getEnv(): TaroGeneral.ENV_TYPE
|
|
69
|
-
|
|
70
|
-
/** 尺寸转换
|
|
71
|
-
* @supported global
|
|
72
|
-
*/
|
|
73
|
-
pxTransform(size: number, designWidth?: number): string
|
|
74
|
-
|
|
75
|
-
/** 尺寸转换初始化
|
|
76
|
-
* @supported global
|
|
77
|
-
*/
|
|
78
|
-
initPxTransform(config: {
|
|
79
|
-
baseFontSize?: number
|
|
80
|
-
deviceRatio?: TaroGeneral.TDeviceRatio
|
|
81
|
-
designWidth?: number
|
|
82
|
-
targetUnit?: string
|
|
83
|
-
unitPrecision?: number
|
|
84
|
-
}): void
|
|
85
|
-
|
|
86
|
-
/** @ignore */
|
|
87
|
-
initAppInfo(appInfo: AppInfo): void
|
|
88
|
-
|
|
89
|
-
/** 小程序获取和 Taro 相关的 App 信息
|
|
90
|
-
* @supported weapp, alipay, jd, qq, swan, tt
|
|
91
|
-
*/
|
|
92
|
-
getAppInfo(): AppInfo
|
|
93
|
-
|
|
94
|
-
/** 小程序引用插件 JS 接口
|
|
95
|
-
* @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
|
|
96
|
-
*/
|
|
97
|
-
requirePlugin(pluginName: string): any
|
|
98
|
-
|
|
99
|
-
/** 获取当前页面实例
|
|
100
|
-
* @supported global
|
|
101
|
-
*/
|
|
102
|
-
getCurrentInstance(): Current
|
|
103
|
-
Current: Current
|
|
104
|
-
|
|
105
|
-
/** Vue3 插件,用于设置 `getApp()` 中的全局变量
|
|
106
|
-
* @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
|
|
107
|
-
* @example
|
|
108
|
-
* ```js
|
|
109
|
-
* // 使用插件
|
|
110
|
-
* const App = createApp(...)
|
|
111
|
-
* App.use(setGlobalDataPlugin, {
|
|
112
|
-
* xxx: 999
|
|
113
|
-
* })
|
|
114
|
-
* // 获取全局变量
|
|
115
|
-
* Taro.getApp().xxx
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
setGlobalDataPlugin: SetGlobalDataPlugin
|
|
119
|
-
|
|
120
|
-
/** 获取自定义 TabBar 对应的 React 或 Vue 组件实例
|
|
121
|
-
* @supported weapp
|
|
122
|
-
* @param page 小程序页面对象,可以通过 Taro.getCurrentInstance().page 获取
|
|
123
|
-
*/
|
|
124
|
-
getTabBar<T>(page: Current['page']): T | undefined
|
|
125
|
-
}
|
|
126
|
-
}
|