Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
b74ce0ad
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b74ce0ad
编写于
2月 18, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(api): promisify
上级
bd546d1e
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
339 addition
and
243 deletion
+339
-243
packages/uni-api/src/helpers/api/callback.ts
packages/uni-api/src/helpers/api/callback.ts
+5
-4
packages/uni-api/src/helpers/api/index.ts
packages/uni-api/src/helpers/api/index.ts
+22
-18
packages/uni-api/src/helpers/api/promise.ts
packages/uni-api/src/helpers/api/promise.ts
+39
-0
packages/uni-api/src/index.ts
packages/uni-api/src/index.ts
+4
-2
packages/uni-api/src/service/ui/createIntersectionObserver.ts
...ages/uni-api/src/service/ui/createIntersectionObserver.ts
+2
-2
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+61
-40
packages/uni-h5/vite.config.ts
packages/uni-h5/vite.config.ts
+24
-19
packages/uni-mp-alipay/dist/uni.api.esm.js
packages/uni-mp-alipay/dist/uni.api.esm.js
+27
-22
packages/uni-mp-baidu/dist/uni.api.esm.js
packages/uni-mp-baidu/dist/uni.api.esm.js
+27
-22
packages/uni-mp-core/src/api/index.ts
packages/uni-mp-core/src/api/index.ts
+3
-6
packages/uni-mp-core/src/api/promise.ts
packages/uni-mp-core/src/api/promise.ts
+4
-16
packages/uni-mp-core/src/api/wrapper.ts
packages/uni-mp-core/src/api/wrapper.ts
+2
-2
packages/uni-mp-qq/dist/uni.api.esm.js
packages/uni-mp-qq/dist/uni.api.esm.js
+27
-22
packages/uni-mp-toutiao/dist/uni.api.esm.js
packages/uni-mp-toutiao/dist/uni.api.esm.js
+27
-22
packages/uni-mp-weixin/dist/uni.api.esm.js
packages/uni-mp-weixin/dist/uni.api.esm.js
+27
-22
packages/uni-quickapp-webview/dist/uni.api.esm.js
packages/uni-quickapp-webview/dist/uni.api.esm.js
+27
-22
packages/vite-plugin-uni/src/config/define.ts
packages/vite-plugin-uni/src/config/define.ts
+2
-1
packages/vite-plugin-uni/src/configResolved/plugins/inject.ts
...ages/vite-plugin-uni/src/configResolved/plugins/inject.ts
+6
-1
packages/vite-plugin-uni/src/index.ts
packages/vite-plugin-uni/src/index.ts
+3
-0
未找到文件。
packages/uni-api/src/helpers/api/callback.ts
浏览文件 @
b74ce0ad
...
...
@@ -70,11 +70,11 @@ export function createKeepAliveApiCallback(name: string, callback: Function) {
)
}
const
API_SUCC
SS
=
'
success
'
const
API_FAIL
=
'
fail
'
const
API_COMPLETE
=
'
complete
'
export
const
API_SUCCE
SS
=
'
success
'
export
const
API_FAIL
=
'
fail
'
export
const
API_COMPLETE
=
'
complete
'
type
CALLBACK_TYPES
=
typeof
API_SUCCSS
|
typeof
API_FAIL
|
typeof
API_COMPLETE
type
CALLBACK_TYPES
=
typeof
API_SUCC
E
SS
|
typeof
API_FAIL
|
typeof
API_COMPLETE
type
ApiCallbacks
=
{
[
key
in
CALLBACK_TYPES
]?:
Function
...
...
@@ -121,6 +121,7 @@ export function createAsyncApiCallback(
callbackId
,
createInvokeCallbackName
(
name
,
callbackId
),
(
res
:
ApiRes
)
=>
{
res
=
res
||
{}
res
.
errMsg
=
normalizeErrMsg
(
res
.
errMsg
,
name
)
isFunction
(
beforeAll
)
&&
beforeAll
(
res
)
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
...
...
packages/uni-api/src/helpers/api/index.ts
浏览文件 @
b74ce0ad
...
...
@@ -4,19 +4,20 @@ import {
createKeepAliveApiCallback
,
invokeCallback
,
}
from
'
./callback
'
import
{
promisify
}
from
'
./promise
'
type
ApiProtocols
=
ApiProtocol
|
ProtocolOptions
[]
export
const
API_TYPE_ON
=
0
export
const
API_TYPE_
SYNC
=
1
export
const
API_TYPE_
A
SYNC
=
2
export
const
API_TYPE_
RETURN
=
3
export
const
API_TYPE_
TASK
=
1
export
const
API_TYPE_SYNC
=
2
export
const
API_TYPE_
ASYNC
=
3
type
API_TYPES
=
|
typeof
API_TYPE_ON
|
typeof
API_TYPE_TASK
|
typeof
API_TYPE_SYNC
|
typeof
API_TYPE_ASYNC
|
typeof
API_TYPE_RETURN
function
validateProtocol
(
_name
:
string
,
...
...
@@ -35,6 +36,11 @@ function wrapperOnApi(name: string, fn: Function) {
fn
.
apply
(
null
,
createKeepAliveApiCallback
(
name
,
callback
))
}
function
wrapperTaskApi
(
name
:
string
,
fn
:
Function
,
options
?:
ApiOptions
)
{
return
(
args
:
Record
<
string
,
any
>
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)])
}
function
wrapperSyncApi
(
fn
:
Function
)
{
return
(...
args
:
any
[])
=>
fn
.
apply
(
null
,
args
)
}
...
...
@@ -42,15 +48,13 @@ function wrapperSyncApi(fn: Function) {
function
wrapperAsyncApi
(
name
:
string
,
fn
:
Function
,
options
?:
ApiOptions
)
{
return
(
args
:
Record
<
string
,
any
>
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
)
return
invokeCallback
(
callbackId
,
fn
.
apply
(
null
,
[
args
,
callbackId
]))
const
res
=
fn
.
apply
(
null
,
[
args
,
callbackId
])
if
(
res
)
{
invokeCallback
(
callbackId
,
res
)
}
}
}
function
wrapperReturnApi
(
name
:
string
,
fn
:
Function
,
options
?:
ApiOptions
)
{
return
(
args
:
Record
<
string
,
any
>
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)])
}
function
wrapperApi
<
T
extends
Function
>
(
fn
:
Function
,
name
?:
string
,
...
...
@@ -73,31 +77,31 @@ export function createOnApi<T extends Function>(
return
createApi
(
API_TYPE_ON
,
name
,
fn
,
protocol
,
options
)
}
export
function
create
Sync
Api
<
T
extends
Function
>
(
export
function
create
Task
Api
<
T
extends
Function
>
(
name
:
string
,
fn
:
T
,
protocol
?:
ApiProtocols
,
options
?:
ApiOptions
)
{
return
createApi
(
API_TYPE_
SYNC
,
name
,
fn
,
protocol
,
options
)
return
createApi
(
API_TYPE_
TASK
,
name
,
fn
,
protocol
,
options
)
}
export
function
create
As
yncApi
<
T
extends
Function
>
(
export
function
create
S
yncApi
<
T
extends
Function
>
(
name
:
string
,
fn
:
T
,
protocol
?:
ApiProtocols
,
options
?:
ApiOptions
)
{
return
createApi
(
API_TYPE_
A
SYNC
,
name
,
fn
,
protocol
,
options
)
return
createApi
(
API_TYPE_SYNC
,
name
,
fn
,
protocol
,
options
)
}
export
function
create
Return
Api
<
T
extends
Function
>
(
export
function
create
Async
Api
<
T
extends
Function
>
(
name
:
string
,
fn
:
T
,
protocol
?:
ApiProtocols
,
options
?:
ApiOptions
)
{
return
createApi
(
API_TYPE_RETURN
,
name
,
fn
,
protocol
,
options
)
return
promisify
(
createApi
(
API_TYPE_ASYNC
,
name
,
fn
,
protocol
,
options
)
)
}
function
createApi
<
T
extends
Function
>
(
...
...
@@ -110,6 +114,8 @@ function createApi<T extends Function>(
switch
(
type
)
{
case
API_TYPE_ON
:
return
wrapperApi
<
T
>
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
,
options
)
case
API_TYPE_TASK
:
return
wrapperApi
<
T
>
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
,
options
)
case
API_TYPE_SYNC
:
return
wrapperApi
<
T
>
(
wrapperSyncApi
(
fn
),
name
,
protocol
,
options
)
case
API_TYPE_ASYNC
:
...
...
@@ -119,7 +125,5 @@ function createApi<T extends Function>(
protocol
,
options
)
case
API_TYPE_RETURN
:
return
wrapperApi
<
T
>
(
wrapperReturnApi
(
name
,
fn
),
name
,
protocol
,
options
)
}
}
packages/uni-api/src/helpers/api/promise.ts
0 → 100644
浏览文件 @
b74ce0ad
import
{
isPlainObject
,
isFunction
}
from
'
@vue/shared
'
import
{
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
}
from
'
./callback
'
const
callbacks
=
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
]
function
hasCallback
(
args
:
unknown
)
{
if
(
isPlainObject
(
args
)
&&
callbacks
.
find
((
cb
)
=>
isFunction
((
args
as
Record
<
string
,
any
>
)[
cb
]))
)
{
return
true
}
return
false
}
export
function
handlePromise
(
promise
:
Promise
<
unknown
>
)
{
if
(
__UNI_PROMISE_API__
)
{
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
]
})
.
catch
((
err
)
=>
[
err
])
}
return
promise
}
export
function
promisify
(
fn
:
Function
)
{
return
(
args
=
{})
=>
{
if
(
hasCallback
(
args
))
{
return
fn
(
args
)
}
return
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
fn
(
Object
.
assign
(
args
,
{
success
:
resolve
,
fail
:
reject
}))
})
)
}
}
packages/uni-api/src/index.ts
浏览文件 @
b74ce0ad
...
...
@@ -24,8 +24,10 @@ export * from './protocols/media/getImageInfo'
// helpers
export
{
createOnApi
,
createTaskApi
,
createSyncApi
,
createAsyncApi
,
createReturnApi
,
}
from
'
./helpers/api
'
export
{
isSyncApi
,
isContextApi
,
promisify
}
from
'
./helpers/promise
'
export
{
handlePromise
}
from
'
./helpers/api/promise
'
export
{
invokeApi
,
wrapperReturnValue
}
from
'
./helpers/interceptor
'
packages/uni-api/src/service/ui/createIntersectionObserver.ts
浏览文件 @
b74ce0ad
...
...
@@ -2,7 +2,7 @@ import { extend } from '@vue/shared'
import
{
ServiceJSBridge
}
from
'
@dcloudio/uni-core
'
import
{
create
Return
Api
}
from
'
../../helpers/api
'
import
{
create
Sync
Api
}
from
'
../../helpers/api
'
import
{
getCurrentPageVm
}
from
'
../utils
'
const
defaultOptions
=
{
...
...
@@ -120,7 +120,7 @@ class ServiceIntersectionObserver {
}
}
export
const
createIntersectionObserver
=
create
Return
Api
<
export
const
createIntersectionObserver
=
create
Sync
Api
<
typeof
uni
.
createIntersectionObserver
>
(
'
createIntersectionObserver
'
,
(
context
?,
options
?)
=>
{
if
(
!
context
)
{
...
...
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
b74ce0ad
...
...
@@ -1335,6 +1335,9 @@ function createKeepAliveApiCallback(name, callback) {
const
id2
=
invokeCallbackId
++
;
return
addInvokeCallback
(
id2
,
createInvokeCallbackName
(
name
,
id2
),
callback
,
true
);
}
const
API_SUCCESS
=
"
success
"
;
const
API_FAIL
=
"
fail
"
;
const
API_COMPLETE
=
"
complete
"
;
function
getApiCallbacks
(
args
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
args
)
{
...
...
@@ -1362,6 +1365,7 @@ function createAsyncApiCallback(name, args = {}, {beforeAll, beforeSuccess} = {}
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
createInvokeCallbackName
(
name
,
callbackId
),
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
"
:ok
"
)
{
...
...
@@ -1374,10 +1378,35 @@ function createAsyncApiCallback(name, args = {}, {beforeAll, beforeSuccess} = {}
});
return
callbackId
;
}
const
callbacks$1
=
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
];
function
hasCallback
(
args
)
{
if
(
isPlainObject
(
args
)
&&
callbacks$1
.
find
((
cb
)
=>
isFunction
(
args
[
cb
])))
{
return
true
;
}
return
false
;
}
function
handlePromise
(
promise
)
{
if
(
__UNI_PROMISE_API__
)
{
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
}).
catch
((
err
)
=>
[
err
]);
}
return
promise
;
}
function
promisify
(
fn
)
{
return
(
args
=
{})
=>
{
if
(
hasCallback
(
args
))
{
return
fn
(
args
);
}
return
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
fn
(
Object
.
assign
(
args
,
{
success
:
resolve
,
fail
:
reject
}));
}));
};
}
const
API_TYPE_ON
=
0
;
const
API_TYPE_
SYNC
=
1
;
const
API_TYPE_
A
SYNC
=
2
;
const
API_TYPE_
RETURN
=
3
;
const
API_TYPE_
TASK
=
1
;
const
API_TYPE_SYNC
=
2
;
const
API_TYPE_
ASYNC
=
3
;
function
validateProtocol
(
_name
,
_args
,
_protocol
)
{
return
true
;
}
...
...
@@ -1387,18 +1416,21 @@ function formatApiArgs(args, options) {
function
wrapperOnApi
(
name
,
fn
)
{
return
(
callback
)
=>
fn
.
apply
(
null
,
createKeepAliveApiCallback
(
name
,
callback
));
}
function
wrapperTaskApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperSyncApi
(
fn
)
{
return
(...
args
)
=>
fn
.
apply
(
null
,
args
);
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
return
invokeCallback
(
callbackId
,
fn
.
apply
(
null
,
[
args
,
callbackId
]));
const
res
=
fn
.
apply
(
null
,
[
args
,
callbackId
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
};
}
function
wrapperReturnApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
return
function
(...
args
)
{
if
(
!
(
process
.
env
.
NODE_ENV
!==
"
production
"
&&
protocol
&&
!
validateProtocol
()))
{
...
...
@@ -1407,24 +1439,21 @@ function wrapperApi(fn, name, protocol, options) {
};
}
function
createSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
/* @__PURE__ */
createApi
(
API_TYPE_SYNC
,
name
,
fn
,
protocol
,
options
);
return
createApi
(
API_TYPE_SYNC
,
name
,
fn
,
protocol
,
options
);
}
function
createAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
/* @__PURE__ */
createApi
(
API_TYPE_ASYNC
,
name
,
fn
,
protocol
,
options
);
}
function
createReturnApi
(
name
,
fn
,
protocol
,
options
)
{
return
/* @__PURE__ */
createApi
(
API_TYPE_RETURN
,
name
,
fn
,
protocol
,
options
);
return
promisify
(
createApi
(
API_TYPE_ASYNC
,
name
,
fn
,
protocol
,
options
));
}
function
createApi
(
type
,
name
,
fn
,
protocol
,
options
)
{
switch
(
type
)
{
case
API_TYPE_ON
:
return
wrapperApi
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_TASK
:
return
wrapperApi
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_SYNC
:
return
wrapperApi
(
wrapperSyncApi
(
fn
),
name
,
protocol
);
case
API_TYPE_ASYNC
:
return
wrapperApi
(
wrapperAsyncApi
(
name
,
fn
,
options
),
name
,
protocol
);
case
API_TYPE_RETURN
:
return
wrapperApi
(
wrapperReturnApi
(
name
,
fn
),
name
,
protocol
);
}
}
const
Base64ToArrayBufferProtocol
=
[
...
...
@@ -1441,10 +1470,10 @@ const ArrayBufferToBase64Protocol = [
required
:
true
}
];
const
base64ToArrayBuffer
=
createSyncApi
(
"
base64ToArrayBuffer
"
,
(
base64
)
=>
{
const
base64ToArrayBuffer
=
/* @__PURE__ */
createSyncApi
(
"
base64ToArrayBuffer
"
,
(
base64
)
=>
{
return
decode
(
base64
);
},
Base64ToArrayBufferProtocol
);
const
arrayBufferToBase64
=
createSyncApi
(
"
arrayBufferToBase64
"
,
(
arrayBuffer
)
=>
{
const
arrayBufferToBase64
=
/* @__PURE__ */
createSyncApi
(
"
arrayBufferToBase64
"
,
(
arrayBuffer
)
=>
{
return
encode
(
arrayBuffer
);
},
ArrayBufferToBase64Protocol
);
const
Upx2pxProtocol
=
[
...
...
@@ -1465,7 +1494,7 @@ function checkDeviceWidth() {
deviceDPR
=
pixelRatio2
;
isIOS
=
platform
===
"
ios
"
;
}
const
upx2px
=
createSyncApi
(
"
upx2px
"
,
(
number
,
newDeviceWidth
)
=>
{
const
upx2px
=
/* @__PURE__ */
createSyncApi
(
"
upx2px
"
,
(
number
,
newDeviceWidth
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
();
}
...
...
@@ -1544,14 +1573,14 @@ function removeHook(hooks, hook) {
hooks
.
splice
(
index2
,
1
);
}
}
const
addInterceptor
=
createSyncApi
(
"
addInterceptor
"
,
(
method
,
interceptor
)
=>
{
const
addInterceptor
=
/* @__PURE__ */
createSyncApi
(
"
addInterceptor
"
,
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
"
string
"
&&
isPlainObject
(
interceptor
))
{
mergeInterceptorHook
(
scopedInterceptors
[
method
]
||
(
scopedInterceptors
[
method
]
=
{}),
interceptor
);
}
else
if
(
isPlainObject
(
method
))
{
mergeInterceptorHook
(
globalInterceptors
,
method
);
}
},
AddInterceptorProtocol
);
const
removeInterceptor
=
createSyncApi
(
"
removeInterceptor
"
,
(
method
,
interceptor
)
=>
{
const
removeInterceptor
=
/* @__PURE__ */
createSyncApi
(
"
removeInterceptor
"
,
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
"
string
"
)
{
if
(
isPlainObject
(
interceptor
))
{
removeInterceptorHook
(
scopedInterceptors
[
method
],
interceptor
);
...
...
@@ -1639,7 +1668,7 @@ class ServiceIntersectionObserver {
},
this
.
_pageId
);
}
}
const
createIntersectionObserver$1
=
createReturn
Api
(
"
createIntersectionObserver
"
,
(
context
,
options
)
=>
{
const
createIntersectionObserver$1
=
/* @__PURE__ */
createSync
Api
(
"
createIntersectionObserver
"
,
(
context
,
options
)
=>
{
if
(
!
context
)
{
context
=
getCurrentPageVm
();
}
...
...
@@ -1687,14 +1716,6 @@ const GetImageInfoProtocol = {
required
:
true
}
};
if
(
!
Promise
.
prototype
.
finally
)
{
Promise
.
prototype
.
finally
=
function
(
onfinally
)
{
const
promise
=
this
.
constructor
;
return
this
.
then
((
value
)
=>
promise
.
resolve
(
onfinally
&&
onfinally
()).
then
(()
=>
value
),
(
reason
)
=>
promise
.
resolve
(
onfinally
&&
onfinally
()).
then
(()
=>
{
throw
reason
;
}));
};
}
function
cssSupports
(
css
)
{
return
window
.
CSS
&&
window
.
CSS
.
supports
&&
window
.
CSS
.
supports
(
css
);
}
...
...
@@ -1703,19 +1724,19 @@ const SCHEMA_CSS = {
"
css.env
"
:
cssSupports
(
"
top:env(a)
"
),
"
css.constant
"
:
cssSupports
(
"
top:constant(a)
"
)
};
const
canIUse
=
createSyncApi
(
"
canIUse
"
,
(
schema
)
=>
{
const
canIUse
=
/* @__PURE__ */
createSyncApi
(
"
canIUse
"
,
(
schema
)
=>
{
if
(
hasOwn
(
SCHEMA_CSS
,
schema
))
{
return
SCHEMA_CSS
[
schema
];
}
return
true
;
},
CanIUseProtocol
);
const
makePhoneCall
=
createAsyncApi
(
"
makePhoneCall
"
,
(
option
)
=>
{
const
makePhoneCall
=
/* @__PURE__ */
createAsyncApi
(
"
makePhoneCall
"
,
(
option
)
=>
{
window
.
location
.
href
=
`tel:
${
option
.
phoneNumber
}
`
;
},
MakePhoneCallProtocol
);
const
ua
=
navigator
.
userAgent
;
const
isAndroid
=
/android/i
.
test
(
ua
);
const
isIOS$1
=
/iphone|ipad|ipod/i
.
test
(
ua
);
const
getSystemInfoSync
=
createSyncApi
(
"
getSystemInfoSync
"
,
()
=>
{
const
getSystemInfoSync
=
/* @__PURE__ */
createSyncApi
(
"
getSystemInfoSync
"
,
()
=>
{
var
screen
=
window
.
screen
;
var
pixelRatio2
=
window
.
devicePixelRatio
;
const
screenFix
=
/^Apple/
.
test
(
navigator
.
vendor
)
&&
typeof
window
.
orientation
===
"
number
"
;
...
...
@@ -1816,16 +1837,16 @@ const getSystemInfoSync = createSyncApi("getSystemInfoSync", () => {
}
};
});
const
getSystemInfo
=
createAsyncApi
(
"
getSystemInfo
"
,
()
=>
{
const
getSystemInfo
=
/* @__PURE__ */
createAsyncApi
(
"
getSystemInfo
"
,
()
=>
{
return
getSystemInfoSync
();
});
const
openDocument
=
createAsyncApi
(
"
openDocument
"
,
(
option
)
=>
{
const
openDocument
=
/* @__PURE__ */
createAsyncApi
(
"
openDocument
"
,
(
option
)
=>
{
window
.
open
(
option
.
filePath
);
},
OpenDocumentProtocol
);
function
_getServiceAddress
()
{
return
window
.
location
.
protocol
+
"
//
"
+
window
.
location
.
host
;
}
const
getImageInfo
=
createAsyncApi
(
"
getImageInfo
"
,
({
src
},
callback
)
=>
{
const
getImageInfo
=
/* @__PURE__ */
createAsyncApi
(
"
getImageInfo
"
,
({
src
},
callback
)
=>
{
const
img
=
new
Image
();
img
.
onload
=
function
()
{
callback
({
...
...
@@ -1842,9 +1863,9 @@ const getImageInfo = createAsyncApi("getImageInfo", ({src}, callback) => {
};
img
.
src
=
src
;
},
GetImageInfoProtocol
,
GetImageInfoOptions
);
const
navigateBack
=
createAsyncApi
(
"
navigateBack
"
,
()
=>
{
const
navigateBack
=
/* @__PURE__ */
createAsyncApi
(
"
navigateBack
"
,
()
=>
{
});
const
navigateTo
=
createAsyncApi
(
"
navigateTo
"
,
(
options
)
=>
{
const
navigateTo
=
/* @__PURE__ */
createAsyncApi
(
"
navigateTo
"
,
(
options
)
=>
{
const
router
=
getApp
().
$router
;
router
.
push
({
path
:
options
.
url
,
...
...
@@ -1852,13 +1873,13 @@ const navigateTo = createAsyncApi("navigateTo", (options) => {
state
:
createPageState
(
"
navigateTo
"
)
});
});
const
redirectTo
=
createAsyncApi
(
"
redirectTo
"
,
()
=>
{
const
redirectTo
=
/* @__PURE__ */
createAsyncApi
(
"
redirectTo
"
,
()
=>
{
});
const
reLaunch
=
createAsyncApi
(
"
reLaunch
"
,
()
=>
{
const
reLaunch
=
/* @__PURE__ */
createAsyncApi
(
"
reLaunch
"
,
()
=>
{
});
const
switchTab
=
createAsyncApi
(
"
switchTab
"
,
()
=>
{
const
switchTab
=
/* @__PURE__ */
createAsyncApi
(
"
switchTab
"
,
()
=>
{
});
const
getRealPath
=
createSyncApi
(
"
getRealPath
"
,
(
path
)
=>
{
const
getRealPath
=
/* @__PURE__ */
createSyncApi
(
"
getRealPath
"
,
(
path
)
=>
{
return
path
;
});
var
api
=
/* @__PURE__ */
Object
.
freeze
({
...
...
packages/uni-h5/vite.config.ts
浏览文件 @
b74ce0ad
...
...
@@ -18,24 +18,26 @@ export default defineConfig({
__DEV__
:
`(process.env.NODE_ENV !== 'production')`
,
__PLATFORM__
:
JSON
.
stringify
(
'
h5
'
),
},
alias
:
[
{
find
:
'
@dcloudio/uni-api
'
,
replacement
:
resolve
(
'
../uni-api/src/index.ts
'
),
},
{
find
:
'
@dcloudio/uni-vue
'
,
replacement
:
resolve
(
'
../uni-vue/src/index.ts
'
),
},
{
find
:
'
@dcloudio/uni-core
'
,
replacement
:
resolve
(
'
../uni-core/src/index.ts
'
),
},
{
find
:
'
@dcloudio/uni-components
'
,
replacement
:
resolve
(
'
../uni-components/src/index.ts
'
),
},
],
resolve
:
{
alias
:
[
{
find
:
'
@dcloudio/uni-api
'
,
replacement
:
resolve
(
'
../uni-api/src/index.ts
'
),
},
{
find
:
'
@dcloudio/uni-vue
'
,
replacement
:
resolve
(
'
../uni-vue/src/index.ts
'
),
},
{
find
:
'
@dcloudio/uni-core
'
,
replacement
:
resolve
(
'
../uni-core/src/index.ts
'
),
},
{
find
:
'
@dcloudio/uni-components
'
,
replacement
:
resolve
(
'
../uni-components/src/index.ts
'
),
},
],
},
plugins
:
[
vue
({
template
:
{
...
...
@@ -54,7 +56,10 @@ export default defineConfig({
preserveEntrySignatures
:
'
strict
'
,
plugins
:
[
replace
({
createApi
:
`/*#__PURE__*/ createApi`
,
createOnApi
:
`/*#__PURE__*/ createOnApi`
,
createTaskApi
:
`/*#__PURE__*/ createTaskApi`
,
createSyncApi
:
`/*#__PURE__*/ createSyncApi`
,
createAsyncApi
:
`/*#__PURE__*/ createAsyncApi`
,
}),
],
output
:
{
...
...
packages/uni-mp-alipay/dist/uni.api.esm.js
浏览文件 @
b74ce0ad
...
...
@@ -83,6 +83,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
createInvokeCallbackName
(
name
,
callbackId
),
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
...
...
@@ -97,10 +98,21 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
return
callbackId
;
}
function
handlePromise
(
promise
)
{
if
(
__UNI_PROMISE_API__
)
{
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
return
promise
;
}
const
API_TYPE_ON
=
0
;
const
API_TYPE_
SYNC
=
1
;
const
API_TYPE_
A
SYNC
=
2
;
const
API_TYPE_
RETURN
=
3
;
const
API_TYPE_
TASK
=
1
;
const
API_TYPE_SYNC
=
2
;
const
API_TYPE_
ASYNC
=
3
;
function
validateProtocol
(
_name
,
_args
,
_protocol
)
{
return
true
;
}
...
...
@@ -110,18 +122,21 @@ function formatApiArgs(args, options) {
function
wrapperOnApi
(
name
,
fn
)
{
return
(
callback
)
=>
fn
.
apply
(
null
,
createKeepAliveApiCallback
(
name
,
callback
));
}
function
wrapperTaskApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperSyncApi
(
fn
)
{
return
(...
args
)
=>
fn
.
apply
(
null
,
args
);
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
return
invokeCallback
(
callbackId
,
fn
.
apply
(
null
,
[
args
,
callbackId
]));
const
res
=
fn
.
apply
(
null
,
[
args
,
callbackId
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
};
}
function
wrapperReturnApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
return
function
(...
args
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
()))
{
...
...
@@ -136,12 +151,12 @@ function createApi(type, name, fn, protocol, options) {
switch
(
type
)
{
case
API_TYPE_ON
:
return
wrapperApi
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_TASK
:
return
wrapperApi
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_SYNC
:
return
wrapperApi
(
wrapperSyncApi
(
fn
),
name
,
protocol
);
case
API_TYPE_ASYNC
:
return
wrapperApi
(
wrapperAsyncApi
(
name
,
fn
,
options
),
name
,
protocol
);
case
API_TYPE_RETURN
:
return
wrapperApi
(
wrapperReturnApi
(
name
,
fn
),
name
,
protocol
);
}
}
...
...
@@ -384,16 +399,6 @@ function isSyncApi(name) {
function
isCallbackApi
(
name
)
{
return
CALLBACK_API_RE
.
test
(
name
)
&&
name
!==
'
onPush
'
;
}
function
handlePromise
(
promise
)
{
if
(
!
__UNI_PROMISE_API__
)
{
return
promise
;
}
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
function
shouldPromise
(
name
)
{
if
(
isContextApi
(
name
)
||
isSyncApi
(
name
)
||
isCallbackApi
(
name
))
{
return
false
;
...
...
@@ -416,17 +421,17 @@ function promisify(name, api) {
if
(
!
isFunction
(
api
))
{
return
api
;
}
return
function
promiseApi
(
options
=
{}
,
...
params
)
{
return
function
promiseApi
(
options
=
{})
{
if
(
isFunction
(
options
.
success
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
complete
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
,
...
params
));
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
api
,
Object
.
assign
({},
options
,
{
success
:
resolve
,
fail
:
reject
,
})
,
...
params
);
}));
})));
};
}
...
...
packages/uni-mp-baidu/dist/uni.api.esm.js
浏览文件 @
b74ce0ad
...
...
@@ -83,6 +83,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
createInvokeCallbackName
(
name
,
callbackId
),
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
...
...
@@ -97,10 +98,21 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
return
callbackId
;
}
function
handlePromise
(
promise
)
{
if
(
__UNI_PROMISE_API__
)
{
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
return
promise
;
}
const
API_TYPE_ON
=
0
;
const
API_TYPE_
SYNC
=
1
;
const
API_TYPE_
A
SYNC
=
2
;
const
API_TYPE_
RETURN
=
3
;
const
API_TYPE_
TASK
=
1
;
const
API_TYPE_SYNC
=
2
;
const
API_TYPE_
ASYNC
=
3
;
function
validateProtocol
(
_name
,
_args
,
_protocol
)
{
return
true
;
}
...
...
@@ -110,18 +122,21 @@ function formatApiArgs(args, options) {
function
wrapperOnApi
(
name
,
fn
)
{
return
(
callback
)
=>
fn
.
apply
(
null
,
createKeepAliveApiCallback
(
name
,
callback
));
}
function
wrapperTaskApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperSyncApi
(
fn
)
{
return
(...
args
)
=>
fn
.
apply
(
null
,
args
);
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
return
invokeCallback
(
callbackId
,
fn
.
apply
(
null
,
[
args
,
callbackId
]));
const
res
=
fn
.
apply
(
null
,
[
args
,
callbackId
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
};
}
function
wrapperReturnApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
return
function
(...
args
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
()))
{
...
...
@@ -136,12 +151,12 @@ function createApi(type, name, fn, protocol, options) {
switch
(
type
)
{
case
API_TYPE_ON
:
return
wrapperApi
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_TASK
:
return
wrapperApi
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_SYNC
:
return
wrapperApi
(
wrapperSyncApi
(
fn
),
name
,
protocol
);
case
API_TYPE_ASYNC
:
return
wrapperApi
(
wrapperAsyncApi
(
name
,
fn
,
options
),
name
,
protocol
);
case
API_TYPE_RETURN
:
return
wrapperApi
(
wrapperReturnApi
(
name
,
fn
),
name
,
protocol
);
}
}
...
...
@@ -384,16 +399,6 @@ function isSyncApi(name) {
function
isCallbackApi
(
name
)
{
return
CALLBACK_API_RE
.
test
(
name
)
&&
name
!==
'
onPush
'
;
}
function
handlePromise
(
promise
)
{
if
(
!
__UNI_PROMISE_API__
)
{
return
promise
;
}
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
function
shouldPromise
(
name
)
{
if
(
isContextApi
(
name
)
||
isSyncApi
(
name
)
||
isCallbackApi
(
name
))
{
return
false
;
...
...
@@ -416,17 +421,17 @@ function promisify(name, api) {
if
(
!
isFunction
(
api
))
{
return
api
;
}
return
function
promiseApi
(
options
=
{}
,
...
params
)
{
return
function
promiseApi
(
options
=
{})
{
if
(
isFunction
(
options
.
success
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
complete
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
,
...
params
));
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
api
,
Object
.
assign
({},
options
,
{
success
:
resolve
,
fail
:
reject
,
})
,
...
params
);
}));
})));
};
}
...
...
packages/uni-mp-core/src/api/index.ts
浏览文件 @
b74ce0ad
import
{
hasOwn
}
from
'
@vue/shared
'
import
{
upx2px
,
addInterceptor
,
removeInterceptor
,
promisify
,
}
from
'
@dcloudio/uni-api
'
import
{
upx2px
,
addInterceptor
,
removeInterceptor
}
from
'
@dcloudio/uni-api
'
import
{
promisify
}
from
'
./promise
'
import
{
initWrapper
}
from
'
./wrapper
'
import
{
MPProtocols
}
from
'
./protocols
'
const
baseApis
=
{
upx2px
,
addInterceptor
,
removeInterceptor
}
...
...
packages/uni-
api/src/helpers
/promise.ts
→
packages/uni-
mp-core/src/api
/promise.ts
浏览文件 @
b74ce0ad
import
{
isFunction
}
from
'
@vue/shared
'
import
{
invokeApi
,
wrapperReturnValue
}
from
'
./interceptor
'
import
{
invokeApi
,
handlePromise
,
wrapperReturnValue
}
from
'
@dcloudio/uni-api
'
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
...
...
@@ -31,17 +31,6 @@ export function isTaskApi(name: string) {
return
TASK_APIS
.
indexOf
(
name
)
!==
-
1
}
function
handlePromise
(
promise
:
Promise
<
any
>
)
{
if
(
!
__UNI_PROMISE_API__
)
{
return
promise
}
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
]
})
.
catch
((
err
)
=>
[
err
])
}
export
function
shouldPromise
(
name
:
string
)
{
if
(
isContextApi
(
name
)
||
isSyncApi
(
name
)
||
isCallbackApi
(
name
))
{
return
false
...
...
@@ -72,13 +61,13 @@ export function promisify(name: string, api: unknown) {
if
(
!
isFunction
(
api
))
{
return
api
}
return
function
promiseApi
(
options
:
Record
<
string
,
any
>
=
{}
,
...
params
:
[]
)
{
return
function
promiseApi
(
options
:
Record
<
string
,
any
>
=
{})
{
if
(
isFunction
(
options
.
success
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
complete
)
)
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
,
...
params
))
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
))
}
return
wrapperReturnValue
(
name
,
...
...
@@ -90,8 +79,7 @@ export function promisify(name: string, api: unknown) {
Object
.
assign
({},
options
,
{
success
:
resolve
,
fail
:
reject
,
}),
...
params
})
)
})
)
...
...
packages/uni-mp-core/src/api/wrapper.ts
浏览文件 @
b74ce0ad
import
{
isFunction
,
isString
,
hasOwn
,
isPlainObject
}
from
'
@vue/shared
'
import
{
isSyncApi
,
isContextApi
}
from
'
@dcloudio/uni-api
'
import
{
MPProtocols
,
MPProtocolArgsValue
,
...
...
@@ -9,6 +7,8 @@ import {
MPProtocolObject
,
}
from
'
./protocols
'
import
{
isSyncApi
,
isContextApi
}
from
'
./promise
'
const
CALLBACKS
=
[
'
success
'
,
'
fail
'
,
'
cancel
'
,
'
complete
'
]
export
function
initWrapper
(
protocols
:
MPProtocols
)
{
...
...
packages/uni-mp-qq/dist/uni.api.esm.js
浏览文件 @
b74ce0ad
...
...
@@ -83,6 +83,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
createInvokeCallbackName
(
name
,
callbackId
),
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
...
...
@@ -97,10 +98,21 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
return
callbackId
;
}
function
handlePromise
(
promise
)
{
if
(
__UNI_PROMISE_API__
)
{
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
return
promise
;
}
const
API_TYPE_ON
=
0
;
const
API_TYPE_
SYNC
=
1
;
const
API_TYPE_
A
SYNC
=
2
;
const
API_TYPE_
RETURN
=
3
;
const
API_TYPE_
TASK
=
1
;
const
API_TYPE_SYNC
=
2
;
const
API_TYPE_
ASYNC
=
3
;
function
validateProtocol
(
_name
,
_args
,
_protocol
)
{
return
true
;
}
...
...
@@ -110,18 +122,21 @@ function formatApiArgs(args, options) {
function
wrapperOnApi
(
name
,
fn
)
{
return
(
callback
)
=>
fn
.
apply
(
null
,
createKeepAliveApiCallback
(
name
,
callback
));
}
function
wrapperTaskApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperSyncApi
(
fn
)
{
return
(...
args
)
=>
fn
.
apply
(
null
,
args
);
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
return
invokeCallback
(
callbackId
,
fn
.
apply
(
null
,
[
args
,
callbackId
]));
const
res
=
fn
.
apply
(
null
,
[
args
,
callbackId
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
};
}
function
wrapperReturnApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
return
function
(...
args
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
()))
{
...
...
@@ -136,12 +151,12 @@ function createApi(type, name, fn, protocol, options) {
switch
(
type
)
{
case
API_TYPE_ON
:
return
wrapperApi
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_TASK
:
return
wrapperApi
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_SYNC
:
return
wrapperApi
(
wrapperSyncApi
(
fn
),
name
,
protocol
);
case
API_TYPE_ASYNC
:
return
wrapperApi
(
wrapperAsyncApi
(
name
,
fn
,
options
),
name
,
protocol
);
case
API_TYPE_RETURN
:
return
wrapperApi
(
wrapperReturnApi
(
name
,
fn
),
name
,
protocol
);
}
}
...
...
@@ -384,16 +399,6 @@ function isSyncApi(name) {
function
isCallbackApi
(
name
)
{
return
CALLBACK_API_RE
.
test
(
name
)
&&
name
!==
'
onPush
'
;
}
function
handlePromise
(
promise
)
{
if
(
!
__UNI_PROMISE_API__
)
{
return
promise
;
}
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
function
shouldPromise
(
name
)
{
if
(
isContextApi
(
name
)
||
isSyncApi
(
name
)
||
isCallbackApi
(
name
))
{
return
false
;
...
...
@@ -416,17 +421,17 @@ function promisify(name, api) {
if
(
!
isFunction
(
api
))
{
return
api
;
}
return
function
promiseApi
(
options
=
{}
,
...
params
)
{
return
function
promiseApi
(
options
=
{})
{
if
(
isFunction
(
options
.
success
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
complete
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
,
...
params
));
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
api
,
Object
.
assign
({},
options
,
{
success
:
resolve
,
fail
:
reject
,
})
,
...
params
);
}));
})));
};
}
...
...
packages/uni-mp-toutiao/dist/uni.api.esm.js
浏览文件 @
b74ce0ad
...
...
@@ -83,6 +83,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
createInvokeCallbackName
(
name
,
callbackId
),
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
...
...
@@ -97,10 +98,21 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
return
callbackId
;
}
function
handlePromise
(
promise
)
{
if
(
__UNI_PROMISE_API__
)
{
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
return
promise
;
}
const
API_TYPE_ON
=
0
;
const
API_TYPE_
SYNC
=
1
;
const
API_TYPE_
A
SYNC
=
2
;
const
API_TYPE_
RETURN
=
3
;
const
API_TYPE_
TASK
=
1
;
const
API_TYPE_SYNC
=
2
;
const
API_TYPE_
ASYNC
=
3
;
function
validateProtocol
(
_name
,
_args
,
_protocol
)
{
return
true
;
}
...
...
@@ -110,18 +122,21 @@ function formatApiArgs(args, options) {
function
wrapperOnApi
(
name
,
fn
)
{
return
(
callback
)
=>
fn
.
apply
(
null
,
createKeepAliveApiCallback
(
name
,
callback
));
}
function
wrapperTaskApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperSyncApi
(
fn
)
{
return
(...
args
)
=>
fn
.
apply
(
null
,
args
);
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
return
invokeCallback
(
callbackId
,
fn
.
apply
(
null
,
[
args
,
callbackId
]));
const
res
=
fn
.
apply
(
null
,
[
args
,
callbackId
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
};
}
function
wrapperReturnApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
return
function
(...
args
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
()))
{
...
...
@@ -136,12 +151,12 @@ function createApi(type, name, fn, protocol, options) {
switch
(
type
)
{
case
API_TYPE_ON
:
return
wrapperApi
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_TASK
:
return
wrapperApi
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_SYNC
:
return
wrapperApi
(
wrapperSyncApi
(
fn
),
name
,
protocol
);
case
API_TYPE_ASYNC
:
return
wrapperApi
(
wrapperAsyncApi
(
name
,
fn
,
options
),
name
,
protocol
);
case
API_TYPE_RETURN
:
return
wrapperApi
(
wrapperReturnApi
(
name
,
fn
),
name
,
protocol
);
}
}
...
...
@@ -384,16 +399,6 @@ function isSyncApi(name) {
function
isCallbackApi
(
name
)
{
return
CALLBACK_API_RE
.
test
(
name
)
&&
name
!==
'
onPush
'
;
}
function
handlePromise
(
promise
)
{
if
(
!
__UNI_PROMISE_API__
)
{
return
promise
;
}
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
function
shouldPromise
(
name
)
{
if
(
isContextApi
(
name
)
||
isSyncApi
(
name
)
||
isCallbackApi
(
name
))
{
return
false
;
...
...
@@ -416,17 +421,17 @@ function promisify(name, api) {
if
(
!
isFunction
(
api
))
{
return
api
;
}
return
function
promiseApi
(
options
=
{}
,
...
params
)
{
return
function
promiseApi
(
options
=
{})
{
if
(
isFunction
(
options
.
success
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
complete
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
,
...
params
));
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
api
,
Object
.
assign
({},
options
,
{
success
:
resolve
,
fail
:
reject
,
})
,
...
params
);
}));
})));
};
}
...
...
packages/uni-mp-weixin/dist/uni.api.esm.js
浏览文件 @
b74ce0ad
...
...
@@ -83,6 +83,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
createInvokeCallbackName
(
name
,
callbackId
),
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
...
...
@@ -97,10 +98,21 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
return
callbackId
;
}
function
handlePromise
(
promise
)
{
if
(
__UNI_PROMISE_API__
)
{
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
return
promise
;
}
const
API_TYPE_ON
=
0
;
const
API_TYPE_
SYNC
=
1
;
const
API_TYPE_
A
SYNC
=
2
;
const
API_TYPE_
RETURN
=
3
;
const
API_TYPE_
TASK
=
1
;
const
API_TYPE_SYNC
=
2
;
const
API_TYPE_
ASYNC
=
3
;
function
validateProtocol
(
_name
,
_args
,
_protocol
)
{
return
true
;
}
...
...
@@ -110,18 +122,21 @@ function formatApiArgs(args, options) {
function
wrapperOnApi
(
name
,
fn
)
{
return
(
callback
)
=>
fn
.
apply
(
null
,
createKeepAliveApiCallback
(
name
,
callback
));
}
function
wrapperTaskApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperSyncApi
(
fn
)
{
return
(...
args
)
=>
fn
.
apply
(
null
,
args
);
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
return
invokeCallback
(
callbackId
,
fn
.
apply
(
null
,
[
args
,
callbackId
]));
const
res
=
fn
.
apply
(
null
,
[
args
,
callbackId
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
};
}
function
wrapperReturnApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
return
function
(...
args
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
()))
{
...
...
@@ -136,12 +151,12 @@ function createApi(type, name, fn, protocol, options) {
switch
(
type
)
{
case
API_TYPE_ON
:
return
wrapperApi
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_TASK
:
return
wrapperApi
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_SYNC
:
return
wrapperApi
(
wrapperSyncApi
(
fn
),
name
,
protocol
);
case
API_TYPE_ASYNC
:
return
wrapperApi
(
wrapperAsyncApi
(
name
,
fn
,
options
),
name
,
protocol
);
case
API_TYPE_RETURN
:
return
wrapperApi
(
wrapperReturnApi
(
name
,
fn
),
name
,
protocol
);
}
}
...
...
@@ -384,16 +399,6 @@ function isSyncApi(name) {
function
isCallbackApi
(
name
)
{
return
CALLBACK_API_RE
.
test
(
name
)
&&
name
!==
'
onPush
'
;
}
function
handlePromise
(
promise
)
{
if
(
!
__UNI_PROMISE_API__
)
{
return
promise
;
}
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
function
shouldPromise
(
name
)
{
if
(
isContextApi
(
name
)
||
isSyncApi
(
name
)
||
isCallbackApi
(
name
))
{
return
false
;
...
...
@@ -416,17 +421,17 @@ function promisify(name, api) {
if
(
!
isFunction
(
api
))
{
return
api
;
}
return
function
promiseApi
(
options
=
{}
,
...
params
)
{
return
function
promiseApi
(
options
=
{})
{
if
(
isFunction
(
options
.
success
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
complete
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
,
...
params
));
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
api
,
Object
.
assign
({},
options
,
{
success
:
resolve
,
fail
:
reject
,
})
,
...
params
);
}));
})));
};
}
...
...
packages/uni-quickapp-webview/dist/uni.api.esm.js
浏览文件 @
b74ce0ad
...
...
@@ -83,6 +83,7 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
createInvokeCallbackName
(
name
,
callbackId
),
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
...
...
@@ -97,10 +98,21 @@ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } =
return
callbackId
;
}
function
handlePromise
(
promise
)
{
if
(
__UNI_PROMISE_API__
)
{
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
return
promise
;
}
const
API_TYPE_ON
=
0
;
const
API_TYPE_
SYNC
=
1
;
const
API_TYPE_
A
SYNC
=
2
;
const
API_TYPE_
RETURN
=
3
;
const
API_TYPE_
TASK
=
1
;
const
API_TYPE_SYNC
=
2
;
const
API_TYPE_
ASYNC
=
3
;
function
validateProtocol
(
_name
,
_args
,
_protocol
)
{
return
true
;
}
...
...
@@ -110,18 +122,21 @@ function formatApiArgs(args, options) {
function
wrapperOnApi
(
name
,
fn
)
{
return
(
callback
)
=>
fn
.
apply
(
null
,
createKeepAliveApiCallback
(
name
,
callback
));
}
function
wrapperTaskApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperSyncApi
(
fn
)
{
return
(...
args
)
=>
fn
.
apply
(
null
,
args
);
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
return
invokeCallback
(
callbackId
,
fn
.
apply
(
null
,
[
args
,
callbackId
]));
const
res
=
fn
.
apply
(
null
,
[
args
,
callbackId
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
};
}
function
wrapperReturnApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
fn
.
apply
(
null
,
[
args
,
createAsyncApiCallback
(
name
,
args
,
options
)]);
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
return
function
(...
args
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
()))
{
...
...
@@ -136,12 +151,12 @@ function createApi(type, name, fn, protocol, options) {
switch
(
type
)
{
case
API_TYPE_ON
:
return
wrapperApi
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_TASK
:
return
wrapperApi
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
);
case
API_TYPE_SYNC
:
return
wrapperApi
(
wrapperSyncApi
(
fn
),
name
,
protocol
);
case
API_TYPE_ASYNC
:
return
wrapperApi
(
wrapperAsyncApi
(
name
,
fn
,
options
),
name
,
protocol
);
case
API_TYPE_RETURN
:
return
wrapperApi
(
wrapperReturnApi
(
name
,
fn
),
name
,
protocol
);
}
}
...
...
@@ -384,16 +399,6 @@ function isSyncApi(name) {
function
isCallbackApi
(
name
)
{
return
CALLBACK_API_RE
.
test
(
name
)
&&
name
!==
'
onPush
'
;
}
function
handlePromise
(
promise
)
{
if
(
!
__UNI_PROMISE_API__
)
{
return
promise
;
}
return
promise
.
then
((
data
)
=>
{
return
[
null
,
data
];
})
.
catch
((
err
)
=>
[
err
]);
}
function
shouldPromise
(
name
)
{
if
(
isContextApi
(
name
)
||
isSyncApi
(
name
)
||
isCallbackApi
(
name
))
{
return
false
;
...
...
@@ -416,17 +421,17 @@ function promisify(name, api) {
if
(
!
isFunction
(
api
))
{
return
api
;
}
return
function
promiseApi
(
options
=
{}
,
...
params
)
{
return
function
promiseApi
(
options
=
{})
{
if
(
isFunction
(
options
.
success
)
||
isFunction
(
options
.
fail
)
||
isFunction
(
options
.
complete
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
,
...
params
));
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
api
,
options
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
api
,
Object
.
assign
({},
options
,
{
success
:
resolve
,
fail
:
reject
,
})
,
...
params
);
}));
})));
};
}
...
...
packages/vite-plugin-uni/src/config/define.ts
浏览文件 @
b74ce0ad
...
...
@@ -2,11 +2,12 @@ import { UserConfig } from 'vite'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
export
function
createDefine
(
_
options
:
VitePluginUniResolvedOptions
options
:
VitePluginUniResolvedOptions
):
UserConfig
[
'
define
'
]
{
return
{
__UNI_WX_API__
:
true
,
__UNI_WXS_API__
:
true
,
__UNI_PROMISE_API__
:
!!
(
options
.
feature
&&
options
.
feature
.
promise
),
__UNI_ROUTER_MODE__
:
JSON
.
stringify
(
'
hash
'
),
}
}
packages/vite-plugin-uni/src/configResolved/plugins/inject.ts
浏览文件 @
b74ce0ad
...
...
@@ -34,7 +34,12 @@ type Injectment = string | [string, string]
export
interface
InjectOptions
extends
UniPluginFilterOptions
{
sourceMap
?:
boolean
[
str
:
string
]:
Injectment
|
InjectOptions
[
'
include
'
]
|
Boolean
|
ViteDevServer
[
str
:
string
]:
|
Injectment
|
InjectOptions
[
'
include
'
]
|
Boolean
|
ViteDevServer
|
any
}
const
debugInject
=
debug
(
'
uni:inject
'
)
...
...
packages/vite-plugin-uni/src/index.ts
浏览文件 @
b74ce0ad
...
...
@@ -10,6 +10,9 @@ import { createConfigResolved } from './configResolved'
import
{
createConfigureServer
}
from
'
./configureServer
'
export
interface
VitePluginUniOptions
{
inputDir
?:
string
feature
?:
{
promise
:
boolean
}
}
export
interface
VitePluginUniResolvedOptions
extends
VitePluginUniOptions
{
root
:
string
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录