utils-uniapp 1.1.1 → 1.1.4
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/lib/http/index.d.ts +193 -64
- package/lib/http/index.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -1
- package/lib/pageStack/index.d.ts +57 -0
- package/lib/pageStack/index.js +1 -0
- package/package.json +1 -1
package/lib/http/index.d.ts
CHANGED
|
@@ -1,108 +1,237 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 请求Content‑Type常量
|
|
3
|
+
*/
|
|
4
|
+
export declare const CONTENT_TYPES: Readonly<{
|
|
5
|
+
/** json格式 */
|
|
3
6
|
JSON: string;
|
|
7
|
+
/** 纯文本 */
|
|
4
8
|
TEXT: string;
|
|
9
|
+
/** url编码表单 */
|
|
5
10
|
FORM_URLENCODED: string;
|
|
11
|
+
/** 文件上传表单 */
|
|
6
12
|
FORM_DATA: string;
|
|
7
13
|
}>;
|
|
8
14
|
|
|
9
|
-
/** uni
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
/** uni请求任务对象,依赖uni‑app全局UniApp命名空间 */
|
|
16
|
+
type UniTask = UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 请求取消控制器(仿axios CancelToken)
|
|
20
|
+
*/
|
|
21
|
+
export declare const CancelToken: {
|
|
22
|
+
caches: Record<string, UniTask | undefined>;
|
|
14
23
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
/**
|
|
25
|
+
* 注册任务
|
|
26
|
+
* @param token 唯一取消令牌
|
|
27
|
+
* @param task uni请求task对象
|
|
28
|
+
*/
|
|
19
29
|
add(token: string, task: UniTask): void;
|
|
20
|
-
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 移除任务缓存
|
|
33
|
+
* @param token 唯一取消令牌
|
|
34
|
+
*/
|
|
21
35
|
delete(token: string): void;
|
|
22
|
-
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @internal 内部私有,请勿外部调用
|
|
39
|
+
* @param token
|
|
40
|
+
*/
|
|
41
|
+
_cancel(token: string): void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 取消全部请求
|
|
45
|
+
*/
|
|
23
46
|
cancelAll(): void;
|
|
24
|
-
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 创建token与取消函数
|
|
50
|
+
* @returns { token:string, cancel:()=>void }
|
|
51
|
+
*/
|
|
25
52
|
source(): { token: string; cancel: () => void };
|
|
26
53
|
};
|
|
27
54
|
|
|
55
|
+
type UniRequestResult = UniApp.RequestSuccessCallbackResult;
|
|
56
|
+
type UniUploadResult = UniApp.UploadFileSuccessCallbackResult;
|
|
57
|
+
type UniDownloadResult = UniApp.DownloadFileSuccessCallbackResult;
|
|
58
|
+
type UniAnyResult = UniRequestResult | UniUploadResult | UniDownloadResult;
|
|
59
|
+
|
|
28
60
|
/**
|
|
29
61
|
* 包装uni异步API为Promise
|
|
30
|
-
* @param type uni接口名称
|
|
31
|
-
* @param opts
|
|
62
|
+
* @param type uni接口名称 request | uploadFile | downloadFile
|
|
63
|
+
* @param opts 请求参数,可以传入 cancelToken 用于请求取消
|
|
64
|
+
* @returns uni接口回调结果Promise
|
|
65
|
+
*/
|
|
66
|
+
export declare function promisifyRequest<T = UniAnyResult>(type: 'request' | 'uploadFile' | 'downloadFile', opts: Record<string, any>): Promise<T>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 开启loading计数
|
|
70
|
+
* @param title loading提示文本,默认:加载中...
|
|
32
71
|
*/
|
|
33
|
-
export function
|
|
34
|
-
type: 'request' | 'uploadFile' | 'downloadFile',
|
|
35
|
-
opts: Record<string, any>
|
|
36
|
-
): Promise<any>;
|
|
72
|
+
export declare function startLoading(title?: string): void;
|
|
37
73
|
|
|
38
|
-
/**
|
|
39
|
-
|
|
74
|
+
/**
|
|
75
|
+
* 关闭loading计数
|
|
76
|
+
*/
|
|
77
|
+
export declare function endLoading(): void;
|
|
40
78
|
|
|
41
|
-
|
|
42
|
-
|
|
79
|
+
// -------------------- 拦截器类型定义(运行时标准化后) --------------------
|
|
80
|
+
/**
|
|
81
|
+
* 请求前置拦截器【标准化后】
|
|
82
|
+
* @param invokeArgs 组装完成即将传给uni的请求参数
|
|
83
|
+
* @param opts normalizeOpts合并后的完整配置
|
|
84
|
+
* @returns 处理后的请求参数
|
|
85
|
+
*/
|
|
86
|
+
type ReqInterceptor = (invokeArgs: Record<string, any>, opts: NormalizeOpts) => Promise<Record<string, any>>;
|
|
43
87
|
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
88
|
+
/**
|
|
89
|
+
* 响应拦截器【标准化后】
|
|
90
|
+
* @param res uni原始响应对象
|
|
91
|
+
* @param opts normalizeOpts合并后的完整配置
|
|
92
|
+
* @param reloadFn 重发当前请求函数,返回Promise
|
|
93
|
+
* @returns 处理后业务数据
|
|
94
|
+
*/
|
|
95
|
+
type ResInterceptor = (res: UniAnyResult, opts: NormalizeOpts, reloadFn: () => Promise<any>) => Promise<any>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 错误拦截器【标准化后】
|
|
99
|
+
* @param err 捕获到的异常对象
|
|
100
|
+
* @param opts normalizeOpts合并后的完整配置
|
|
101
|
+
* @returns 返回非undefined代表错误已接管;返回undefined会继续抛出异常
|
|
102
|
+
*/
|
|
103
|
+
type ErrInterceptor = (err: any, opts: NormalizeOpts) => Promise<any>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 用户传入拦截器:支持单个函数 / 函数数组,交由 normalizeInterceptor + composeAsync合并
|
|
107
|
+
*/
|
|
108
|
+
type UserReqInterceptor = ReqInterceptor | ReqInterceptor[];
|
|
109
|
+
type UserResInterceptor = ResInterceptor | ResInterceptor[];
|
|
110
|
+
type UserErrInterceptor = ErrInterceptor | ErrInterceptor[];
|
|
111
|
+
|
|
112
|
+
// 导出拦截器类型别名,供业务直接 import type 使用
|
|
113
|
+
export type { ReqInterceptor, ResInterceptor, ErrInterceptor, UserReqInterceptor, UserResInterceptor, UserErrInterceptor };
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* normalizeOpts标准化之后的请求额外配置对象【内部运行时】
|
|
117
|
+
*/
|
|
118
|
+
export interface NormalizeOpts {
|
|
119
|
+
/** post请求是否使用urlencoded表单格式 */
|
|
120
|
+
qs: boolean;
|
|
121
|
+
/** 是否开启默认错误弹窗提示 */
|
|
122
|
+
showError: boolean;
|
|
123
|
+
/** 是否开启接口缓存 */
|
|
124
|
+
isCache: boolean;
|
|
125
|
+
/** 缓存key前缀;不传/空字符串/undefined默认使用api;设置cacheKey时此配置无效 */
|
|
126
|
+
cachePrefix?: string;
|
|
127
|
+
/** 完整缓存key,传入则完全覆盖,优先级高于cachePrefix */
|
|
128
|
+
cacheKey: string;
|
|
129
|
+
/** 缓存过期时间,单位ms */
|
|
130
|
+
cacheExpire: number;
|
|
131
|
+
/** loading提示文案 */
|
|
132
|
+
loadingText: string;
|
|
133
|
+
/** 是否开启loading */
|
|
134
|
+
loading: boolean;
|
|
135
|
+
/** 请求前置拦截器(compose组合完成的单个函数) */
|
|
136
|
+
reqInterceptor: ReqInterceptor;
|
|
137
|
+
/** 响应拦截器(compose组合完成的单个函数) */
|
|
138
|
+
resInterceptor: ResInterceptor;
|
|
139
|
+
/** 错误拦截器(compose组合完成的单个函数) */
|
|
140
|
+
errInterceptor: ErrInterceptor;
|
|
141
|
+
/** 允许扩展自定义字段 */
|
|
48
142
|
[key: string]: any;
|
|
49
143
|
}
|
|
50
144
|
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
145
|
+
/**
|
|
146
|
+
* 业务侧传入配置【外部用户参数,支持拦截器数组】
|
|
147
|
+
* 经过内部 normalizeOpts 之后转换为 NormalizeOpts
|
|
148
|
+
*/
|
|
149
|
+
export interface UserRequestOpts {
|
|
150
|
+
/** post请求是否使用urlencoded表单格式 */
|
|
54
151
|
qs?: boolean;
|
|
55
|
-
/**
|
|
152
|
+
/** 是否开启默认错误弹窗提示 */
|
|
56
153
|
showError?: boolean;
|
|
57
|
-
/**
|
|
154
|
+
/** 是否开启接口缓存 */
|
|
58
155
|
isCache?: boolean;
|
|
59
|
-
/**
|
|
156
|
+
/** 缓存key前缀;不传/空字符串/undefined默认使用api;设置cacheKey时此配置无效 */
|
|
157
|
+
cachePrefix?: string;
|
|
158
|
+
/** 完整缓存key,传入则完全覆盖,优先级高于cachePrefix */
|
|
60
159
|
cacheKey?: string;
|
|
61
|
-
/**
|
|
160
|
+
/** 缓存过期时间,单位ms */
|
|
62
161
|
cacheExpire?: number;
|
|
63
|
-
/** loading
|
|
162
|
+
/** loading提示文案 */
|
|
64
163
|
loadingText?: string;
|
|
65
|
-
/**
|
|
164
|
+
/** 是否开启loading */
|
|
66
165
|
loading?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
reqInterceptor?:
|
|
69
|
-
/**
|
|
70
|
-
resInterceptor?:
|
|
71
|
-
/**
|
|
72
|
-
errInterceptor?:
|
|
166
|
+
/** 请求前置拦截器,支持单个函数或函数数组 */
|
|
167
|
+
reqInterceptor?: UserReqInterceptor;
|
|
168
|
+
/** 响应拦截器,支持单个函数或函数数组 */
|
|
169
|
+
resInterceptor?: UserResInterceptor;
|
|
170
|
+
/** 错误拦截器,支持单个函数或函数数组 */
|
|
171
|
+
errInterceptor?: UserErrInterceptor;
|
|
172
|
+
/** 允许扩展自定义字段 */
|
|
73
173
|
[key: string]: any;
|
|
74
174
|
}
|
|
75
175
|
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
176
|
+
/**
|
|
177
|
+
* createRequest返回的请求实例对象
|
|
178
|
+
*/
|
|
179
|
+
interface RequestInstance {
|
|
180
|
+
/**
|
|
181
|
+
* 基础请求方法
|
|
182
|
+
* @param url 请求地址
|
|
183
|
+
* @param method 请求方法,如 GET / POST / PUT 等,支持自定义method字符串
|
|
184
|
+
* @param params 请求参数,允许传null
|
|
185
|
+
* @param config uni底层请求配置(header、timeout等)
|
|
186
|
+
* @param options 请求扩展配置(loading、缓存、拦截器等,支持拦截器数组)
|
|
187
|
+
*/
|
|
188
|
+
(url: string, method: string, params?: any | null, config?: Record<string, any>, options?: UserRequestOpts): Promise<any>;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* get快捷方法
|
|
192
|
+
* @param url 请求地址
|
|
193
|
+
* @param params 请求参数,允许传null
|
|
194
|
+
* @param config uni底层请求配置
|
|
195
|
+
* @param options 请求扩展配置
|
|
196
|
+
*/
|
|
197
|
+
get(url: string, params?: any | null, config?: Record<string, any>, options?: UserRequestOpts): Promise<any>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* post快捷方法
|
|
201
|
+
* @param url 请求地址
|
|
202
|
+
* @param params 请求参数,允许传null
|
|
203
|
+
* @param config uni底层请求配置
|
|
204
|
+
* @param options 请求扩展配置
|
|
205
|
+
*/
|
|
206
|
+
post(url: string, params?: any | null, config?: Record<string, any>, options?: UserRequestOpts): Promise<any>;
|
|
207
|
+
}
|
|
82
208
|
|
|
83
209
|
/**
|
|
84
210
|
* 创建常规http请求实例(get/post)
|
|
85
|
-
* @param defaultConfig
|
|
86
|
-
* @param defaultOpts
|
|
211
|
+
* @param defaultConfig 全局基础配置 baseURL、headers等
|
|
212
|
+
* @param defaultOpts 全局默认扩展配置 loading、缓存、拦截器等,拦截器支持数组
|
|
213
|
+
* @returns RequestInstance 请求实例
|
|
87
214
|
*/
|
|
88
|
-
export function createRequest(defaultConfig
|
|
215
|
+
export declare function createRequest(defaultConfig: Record<string, any>, defaultOpts?: UserRequestOpts): RequestInstance;
|
|
89
216
|
|
|
90
217
|
/**
|
|
91
218
|
* 创建上传文件实例
|
|
92
|
-
* @param defaultConfig
|
|
93
|
-
* @param defaultOpts
|
|
219
|
+
* @param defaultConfig 全局基础配置 baseURL、headers等
|
|
220
|
+
* @param defaultOpts 全局默认扩展配置 loading、缓存、拦截器等,拦截器支持数组
|
|
221
|
+
* @returns 上传函数
|
|
94
222
|
*/
|
|
95
|
-
export function createUploadFile(
|
|
96
|
-
defaultConfig
|
|
97
|
-
defaultOpts?:
|
|
98
|
-
): (url: string, params: { filePath: string; keyName?: string; [key: string]: any }, config?:
|
|
223
|
+
export declare function createUploadFile(
|
|
224
|
+
defaultConfig: Record<string, any>,
|
|
225
|
+
defaultOpts?: UserRequestOpts
|
|
226
|
+
): (url: string, params: { filePath: string; keyName?: string; [key: string]: any }, config?: Record<string, any>, options?: UserRequestOpts) => Promise<any>;
|
|
99
227
|
|
|
100
228
|
/**
|
|
101
229
|
* 创建下载文件实例
|
|
102
|
-
* @param defaultConfig
|
|
103
|
-
* @param defaultOpts
|
|
230
|
+
* @param defaultConfig 全局基础配置 baseURL、headers等
|
|
231
|
+
* @param defaultOpts 全局默认扩展配置 loading、缓存、拦截器等,拦截器支持数组
|
|
232
|
+
* @returns 下载函数
|
|
104
233
|
*/
|
|
105
|
-
export function createDownloadFile(
|
|
106
|
-
defaultConfig
|
|
107
|
-
defaultOpts?:
|
|
108
|
-
): (url: string, params?: Record<string, any>, config?:
|
|
234
|
+
export declare function createDownloadFile(
|
|
235
|
+
defaultConfig: Record<string, any>,
|
|
236
|
+
defaultOpts?: UserRequestOpts
|
|
237
|
+
): (url: string, params?: Record<string, any>, config?: Record<string, any>, options?: UserRequestOpts) => Promise<any>;
|
package/lib/http/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("../index-b81565a7.js"),A=require("../object/index.js"),O=Object.freeze({JSON:"application/json;charset=UTF-8",TEXT:"text/plain;charset=UTF-8",FORM_URLENCODED:"application/x-www-form-urlencoded;charset=UTF-8",FORM_DATA:"multipart/form-data"}),m={caches:Object.create(null),add(e,t){this.caches[e]=t},delete(e){Reflect.deleteProperty(this.caches,e)},_cancel(e){const t=this.caches[e];typeof(t==null?void 0:t.abort)=="function"&&t.abort()},cancelAll(){Object.values(this.caches).forEach(e=>{typeof(e==null?void 0:e.abort)=="function"&&e.abort()}),this.caches=Object.create(null)},source(){const e=`${Date.now()}-${C.getRandomStr(16)}`;return{token:e,cancel:()=>this._cancel(e)}}};function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("../index-b81565a7.js"),A=require("../object/index.js"),O=Object.freeze({JSON:"application/json;charset=UTF-8",TEXT:"text/plain;charset=UTF-8",FORM_URLENCODED:"application/x-www-form-urlencoded;charset=UTF-8",FORM_DATA:"multipart/form-data"}),m={caches:Object.create(null),add(e,t){this.caches[e]=t},delete(e){Reflect.deleteProperty(this.caches,e)},_cancel(e){const t=this.caches[e];typeof(t==null?void 0:t.abort)=="function"&&t.abort()},cancelAll(){Object.values(this.caches).forEach(e=>{typeof(e==null?void 0:e.abort)=="function"&&e.abort()}),this.caches=Object.create(null)},source(){const e=`${Date.now()}-${C.getRandomStr(16)}`;return{token:e,cancel:()=>this._cancel(e)}}};function x(e,t){return new Promise((c,n)=>{const r=uni[e]({...t,success(o){if(o.statusCode>=200&&o.statusCode<300)return c(o);n({type:"fail",res:o})},fail(o){n({type:"fail",res:o})},complete(){t.cancelToken&&m.delete(t.cancelToken)}});t.cancelToken&&m.add(t.cancelToken,r)})}let R=0,v=!1;function N(e){v||(v=!0,uni.showLoading({title:e,mask:!0}))}function P(){v&&(v=!1,uni.hideLoading())}function j(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"加载中...";R++,R===1&&N(e)}function D(){R>0&&R--,R===0&&P()}function _(e,t){return function(c,n,r,o){return e(c,t,n,r,o)}}function w(e){return typeof e=="function"?e:()=>e||{}}function k(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},c=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const n=w(t.headers)(),r=w(c.headers)(),o={...t,...c,headers:{...n,...r}},{headers:a,...s}=o;return{urlRes:e.startsWith("http")?e:o.baseURL?o.baseURL+e:e,headers:a,configRes:s}}function U(e){return typeof e=="function"?[e]:Array.isArray(e)?e.filter(t=>typeof t=="function"):[]}function F(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},c=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};const n={qs:!0,showError:!0,isCache:!1,cacheExpire:1e3*60*60*1,loadingText:e.loadingText,loading:!0,reqInterceptor:r=>r,resInterceptor:r=>r,errInterceptor:()=>{},...t,...c};if(!n.cacheKey){const r=(n.cachePrefix||"api").replace(/:$/,"");n.cacheKey=`${r}:${e.url}`}return["reqInterceptor","resInterceptor","errInterceptor"].forEach(r=>{const o=[...U(t[r]),...U(c[r])];n[r]=o.length?C.composeAsync(...o):a=>a}),n}function q(e,t){const c=Array.from(t);return()=>e(...A.cloneDeepWithDescriptors(c))}function E(e,t,c,n,r){return b.apply(this,arguments)}function b(){return b=C._asyncToGenerator(function*(e,t,c,n,r){let o;n.loading&&(j(n.loadingText),o=()=>{D(),o=null});try{var a;const u=yield n.reqInterceptor(c,n),l=yield e(t,u);return(a=o)===null||a===void 0||a(),yield n.resInterceptor(l,n,r)}catch(u){var s;(s=o)===null||s===void 0||s();const l=yield n.errInterceptor(u,n);return l!==void 0?l:Promise.reject(u)}}),b.apply(this,arguments)}function S(e,t){function c(n,r,o,a,s){const u=m.source(),l=q(c,arguments),i=F({url:n,loadingText:"加载中..."},t,s),{urlRes:y,headers:T,configRes:h}=k(n,e,a);if(i.isCache){const d=C.getCache(i.cacheKey);if(d)return Promise.resolve(d)}const p=r.toUpperCase()==="GET"?O.JSON:i.qs?O.FORM_URLENCODED:O.JSON,g={cancelToken:u.token,method:r,url:y,data:o,header:{"Content-Type":p,...T},...h};return E(x,"request",g,i,l).then(d=>(i.isCache&&C.setCache(i.cacheKey,d,i.cacheExpire),d))}return c.get=_(c,"get"),c.post=_(c,"post"),c}function L(e,t){return function c(n,r,o,a){const s=m.source(),u=q(c,arguments),l=F({loadingText:"上传中..."},t,a),{urlRes:i,headers:y,configRes:T}=k(n,e,o),{keyName:h="file",filePath:f,...p}={keyName:"file",...r};if(!f||!f.startsWith("http://tmp")&&!f.startsWith("wxfile://tmp"))return Promise.resolve({data:f});const g={cancelToken:s.token,url:i,filePath:f,name:h,formData:p,header:{...y},...T};return E(x,"uploadFile",g,l,u)}}function $(e,t){return function c(n,r,o,a){const s=m.source(),u=q(c,arguments),l=F({loadingText:"下载中..."},t,a),{urlRes:i,headers:y,configRes:T}=k(n,e,o);let h=i;if(r&&typeof r=="object"){const p=Object.entries(r).filter(g=>{let[,d]=g;return d!=null&&d!==""}).map(g=>{let[d,I]=g;return`${encodeURIComponent(d)}=${encodeURIComponent(I)}`}).join("&");p&&(h+=(h.includes("?")?"&":"?")+p)}const f={cancelToken:s.token,url:h,header:{...y},...T};return E(x,"downloadFile",f,l,u)}}exports.CONTENT_TYPES=O;exports.CancelToken=m;exports.createDownloadFile=$;exports.createRequest=S;exports.createUploadFile=L;exports.endLoading=D;exports.promisifyRequest=x;exports.startLoading=j;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./aliPay/index.js"),a=require("./array/index.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./aliPay/index.js"),a=require("./array/index.js"),s=require("./date/index.js"),o=require("./fs/index.js"),g=require("./getLocation/index.js"),r=require("./http/index.js"),e=require("./index-b81565a7.js"),n=require("./object/index.js"),t=require("./pageStack/index.js"),i=require("./validate/index.js"),d=require("./index-9456b3d9.js"),m=require("./lodash");Object.assign(exports,m);exports.alipaySubmit=c.alipaySubmit;exports.exchangeArrP=a.exchangeArrP;exports.filterTree=a.filterTree;exports.findTreeItem=a.findTreeItem;exports.flatWithKey=a.flatWithKey;exports.getTreePath=a.getTreePath;exports.groupBy=a.groupBy;exports.reverseForEach=a.reverseForEach;exports.treeItemSetParent=a.treeItemSetParent;exports.dateFormat=s.dateFormat;exports.getDate=s.getDate;exports.$fs=o.$fs;exports.chooseImg=o.chooseImg;exports.getArraybufferTempPath=o.getArraybufferTempPath;exports.getImgBase64Prefix=o.getImgBase64Prefix;exports.readFile=o.readFile;exports.saveImageToPhotosAlbum=o.saveImageToPhotosAlbum;exports.writeFile=o.writeFile;exports.getLocation=g.getLocation;exports.openLocation=g.openLocation;exports.CONTENT_TYPES=r.CONTENT_TYPES;exports.CancelToken=r.CancelToken;exports.createDownloadFile=r.createDownloadFile;exports.createRequest=r.createRequest;exports.createUploadFile=r.createUploadFile;exports.endLoading=r.endLoading;exports.promisifyRequest=r.promisifyRequest;exports.startLoading=r.startLoading;exports.compareVersion=e.compareVersion;exports.compose=e.compose;exports.composeAsync=e.composeAsync;exports.debounce=e.debounce;exports.debouncePromise=e.debouncePromise;exports.decodeURIParams=e.decodeURIParams;exports.encodeURIParams=e.encodeURIParams;exports.getCache=e.getCache;exports.getOnLoadParams=e.getOnLoadParams;exports.getPascalCase=e.getPascalCase;exports.getQueryParams=e.getQueryParams;exports.getQueryParamsFromHash=e.getQueryParamsFromHash;exports.getQueryParamsFromSearch=e.getQueryParamsFromSearch;exports.getRandom=e.getRandom;exports.getRandomStr=e.getRandomStr;exports.pipe=e.pipe;exports.pipeAsync=e.pipeAsync;exports.randomColor=e.randomColor;exports.removeCache=e.removeCache;exports.renewCache=e.renewCache;exports.setCache=e.setCache;exports.throttle=e.throttle;exports.toQueryString=e.toQueryString;exports.cloneDeepWithDescriptors=n.cloneDeepWithDescriptors;exports.getRawType=n.getRawType;exports.hasOwnProperty=n.hasOwnProperty;exports.backToRoute=t.backToRoute;exports.findPageByRoute=t.findPageByRoute;exports.getCurrentPage=t.getCurrentPage;exports.getCurrentPageOptions=t.getCurrentPageOptions;exports.getCurrentRoute=t.getCurrentRoute;exports.getPageStack=t.getPageStack;exports.getPageVm=t.getPageVm;exports.getPrevPage=t.getPrevPage;exports.getPrevRoute=t.getPrevRoute;exports.isExternal=i.isExternal;exports.validDate=i.validDate;exports.validIDCard=i.validIDCard;exports.validPhone=i.validPhone;exports.validPostalCode=i.validPostalCode;exports.validURL=i.validURL;exports.wx=d.index;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取当前页面实例
|
|
3
|
+
* @returns 当前页面对象,栈空返回 null
|
|
4
|
+
*/
|
|
5
|
+
export declare function getCurrentPage(): UniApp.PageInstance | null;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 获取上一页页面实例
|
|
9
|
+
* @returns 上一页实例,无则 null
|
|
10
|
+
*/
|
|
11
|
+
export declare function getPrevPage(): UniApp.PageInstance | null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 获取完整页面栈副本
|
|
15
|
+
* @returns 页面实例数组副本
|
|
16
|
+
*/
|
|
17
|
+
export declare function getPageStack(): UniApp.PageInstance[];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 获取当前页面路由(不带 query 参数)
|
|
21
|
+
* @returns 路由字符串,栈空返回 null
|
|
22
|
+
*/
|
|
23
|
+
export declare function getCurrentRoute(): string | null;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 获取当前页面 onLoad options 参数
|
|
27
|
+
* @returns 页面启动参数,栈空返回 null
|
|
28
|
+
*/
|
|
29
|
+
export declare function getCurrentPageOptions(): Record<string, string | undefined> | null;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 获取上一页路由
|
|
33
|
+
* @returns 路由字符串,无上一页返回 null
|
|
34
|
+
*/
|
|
35
|
+
export declare function getPrevRoute(): string | null;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 根据路由在页面栈中查找页面对象
|
|
39
|
+
* @param route 页面路由,支持带/不带开头 /
|
|
40
|
+
* @returns 找到返回页面对象,否则 null
|
|
41
|
+
*/
|
|
42
|
+
export declare function findPageByRoute(route: string): UniApp.PageInstance | null;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 回退到指定路由页面(封装 navigateBack Promise)
|
|
46
|
+
* @param targetRoute 目标页面路由,支持带/不带 /
|
|
47
|
+
* @param useReLaunchFallback 找不到页面是否开启reLaunch兜底,默认false;reLaunch会清空整个页面栈
|
|
48
|
+
* @returns true 使用navigateBack回退;false 未找到页面或执行兜底跳转
|
|
49
|
+
*/
|
|
50
|
+
export declare function backToRoute(targetRoute: string, useReLaunchFallback?: boolean): Promise<boolean>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 安全获取页面Vue组件$vm实例
|
|
54
|
+
* @param pageIns 页面对象实例
|
|
55
|
+
* @returns Vue组件实例,不存在/已销毁返回null
|
|
56
|
+
*/
|
|
57
|
+
export declare function getPageVm(pageIns: UniApp.PageInstance | null | undefined): any | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function a(){try{const t=getCurrentPages();return t.length?t[t.length-1]:null}catch{return null}}function g(){try{const t=getCurrentPages();return t.length<2?null:t[t.length-2]}catch{return null}}function c(){try{return[...getCurrentPages()]}catch{return[]}}function s(){try{var t;const n=a();return(t=n==null?void 0:n.route)!==null&&t!==void 0?t:null}catch{return null}}function P(){try{var t;const n=a();return(t=n==null?void 0:n.options)!==null&&t!==void 0?t:null}catch{return null}}function d(){try{var t;const n=g();return(t=n==null?void 0:n.route)!==null&&t!==void 0?t:null}catch{return null}}function i(t){return typeof t!="string"?"":t.replace(/^\/+/,"")}function h(t){try{var n;const e=c(),r=i(t);return r&&(n=e.find(u=>u.route===r))!==null&&n!==void 0?n:null}catch{return null}}function y(t){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;return new Promise(e=>{try{const r=c(),u=i(t);if(!u){e(!1);return}const l=r.findIndex(f=>f.route===u);if(l===r.length-1){e(!0);return}if(l===-1){n?uni.reLaunch({url:`/${u}`,success:()=>e(!1),fail:()=>e(!1)}):e(!1);return}const o=r.length-1-l;uni.navigateBack({delta:o,success:()=>e(!0),fail:()=>e(!1)})}catch{e(!1)}})}function v(t){try{var n;return t&&(n=t.$vm)!==null&&n!==void 0?n:null}catch{return null}}exports.backToRoute=y;exports.findPageByRoute=h;exports.getCurrentPage=a;exports.getCurrentPageOptions=P;exports.getCurrentRoute=s;exports.getPageStack=c;exports.getPageVm=v;exports.getPrevPage=g;exports.getPrevRoute=d;
|