Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
059d3dc4
U
uni-app
项目概览
MuGuiLin
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
059d3dc4
编写于
4月 06, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: defineAsyncApi
上级
959060f0
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
241 addition
and
215 deletion
+241
-215
packages/uni-api/src/helpers/api/index.ts
packages/uni-api/src/helpers/api/index.ts
+70
-25
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+48
-52
packages/uni-h5/src/service/api/device/getSystemInfo.ts
packages/uni-h5/src/service/api/device/getSystemInfo.ts
+1
-1
packages/uni-h5/src/service/api/device/makePhoneCall.ts
packages/uni-h5/src/service/api/device/makePhoneCall.ts
+3
-2
packages/uni-h5/src/service/api/file/openDocument.ts
packages/uni-h5/src/service/api/file/openDocument.ts
+3
-2
packages/uni-h5/src/service/api/media/getImageInfo.ts
packages/uni-h5/src/service/api/media/getImageInfo.ts
+14
-15
packages/uni-h5/src/service/api/route/navigateBack.ts
packages/uni-h5/src/service/api/route/navigateBack.ts
+12
-12
packages/uni-h5/src/service/api/route/navigateTo.ts
packages/uni-h5/src/service/api/route/navigateTo.ts
+1
-2
packages/uni-h5/src/service/api/route/reLaunch.ts
packages/uni-h5/src/service/api/route/reLaunch.ts
+1
-2
packages/uni-h5/src/service/api/route/redirectTo.ts
packages/uni-h5/src/service/api/route/redirectTo.ts
+1
-2
packages/uni-h5/src/service/api/route/switchTab.ts
packages/uni-h5/src/service/api/route/switchTab.ts
+1
-2
packages/uni-h5/src/service/api/route/utils.ts
packages/uni-h5/src/service/api/route/utils.ts
+13
-14
packages/uni-mp-alipay/dist/uni.api.esm.js
packages/uni-mp-alipay/dist/uni.api.esm.js
+9
-11
packages/uni-mp-baidu/dist/uni.api.esm.js
packages/uni-mp-baidu/dist/uni.api.esm.js
+9
-11
packages/uni-mp-qq/dist/uni.api.esm.js
packages/uni-mp-qq/dist/uni.api.esm.js
+9
-11
packages/uni-mp-toutiao/dist/uni.api.esm.js
packages/uni-mp-toutiao/dist/uni.api.esm.js
+9
-11
packages/uni-mp-weixin/dist/uni.api.esm.js
packages/uni-mp-weixin/dist/uni.api.esm.js
+9
-11
packages/uni-quickapp-webview/dist/uni.api.esm.js
packages/uni-quickapp-webview/dist/uni.api.esm.js
+9
-11
packages/vite-plugin-uni/src/utils/define.ts
packages/vite-plugin-uni/src/utils/define.ts
+19
-18
未找到文件。
packages/uni-api/src/helpers/api/index.ts
浏览文件 @
059d3dc4
import
{
isPlainObject
}
from
'
@vue/shared
'
import
{
extend
,
isPlainObject
}
from
'
@vue/shared
'
import
{
ApiOptions
,
ApiProtocols
}
from
'
../../protocols/type
'
import
{
API_TYPE_ON_PROTOCOLS
,
validateProtocols
}
from
'
../protocol
'
import
{
...
...
@@ -48,18 +48,20 @@ function wrapperSyncApi(fn: Function) {
return
(...
args
:
any
[])
=>
fn
.
apply
(
null
,
args
)
}
function
wrapperAsyncApi
(
name
:
string
,
fn
:
Function
,
options
?:
ApiOptions
)
{
function
wrapperAsyncApi
(
name
:
string
,
fn
:
(
args
:
unknown
)
=>
Promise
<
unknown
>
,
options
?:
ApiOptions
)
{
return
(
args
:
Record
<
string
,
any
>
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
)
const
res
=
fn
.
apply
(
null
,
[
args
,
(
res
:
unknown
)
=>
{
invokeCallback
(
callbackId
,
res
)
},
])
if
(
res
)
{
invokeCallback
(
callbackId
,
res
)
}
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
)
fn
(
args
)
.
then
((
res
)
=>
{
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}))
})
.
catch
((
err
)
=>
{
invokeCallback
(
id
,
{
errMsg
:
name
+
'
:fail
'
+
(
err
?
'
'
+
err
:
''
)
})
})
}
}
...
...
@@ -91,7 +93,7 @@ export function defineOnApi<T extends Function>(
fn
,
__DEV__
?
API_TYPE_ON_PROTOCOLS
:
undefined
,
options
)
)
as
T
}
export
function
defineTaskApi
<
T
extends
Function
>
(
...
...
@@ -106,7 +108,7 @@ export function defineTaskApi<T extends Function>(
fn
,
__DEV__
?
protocol
:
undefined
,
options
)
)
as
T
}
export
function
defineSyncApi
<
T
extends
Function
>
(
...
...
@@ -121,37 +123,80 @@ export function defineSyncApi<T extends Function>(
fn
,
__DEV__
?
protocol
:
undefined
,
options
)
)
as
T
}
interface
AsyncMethodOptionLike
{
success
?:
(...
args
:
any
[])
=>
void
}
type
PromisifySuccessResult
<
P
,
R
>
=
P
extends
{
success
:
any
}
?
void
:
P
extends
{
fail
:
any
}
?
void
:
P
extends
{
complete
:
any
}
?
void
:
Promise
<
R
>
type
AsyncApiLike
=
(
args
:
any
)
=>
Promise
<
unknown
>
|
void
type
AsyncApiOptions
<
T
extends
AsyncApiLike
>
=
Parameters
<
T
>
[
0
]
type
AsyncApiRes
<
T
extends
AsyncMethodOptionLike
>
=
Parameters
<
Exclude
<
T
[
'
success
'
],
undefined
>
>
[
0
]
type
AsyncApiRequired
<
T
extends
AsyncMethodOptionLike
>
=
<
P
extends
T
>
(
args
:
P
)
=>
PromisifySuccessResult
<
P
,
AsyncApiRes
<
T
>>
type
AsyncApiOptional
<
T
extends
AsyncMethodOptionLike
>
=
<
P
extends
T
>
(
args
?:
P
)
=>
PromisifySuccessResult
<
P
,
AsyncApiRes
<
T
>>
interface
AsyncApiOptionalOptions
{
success
?:
any
fail
?:
any
complete
?:
any
}
export
function
defineAsyncApi
<
T
extends
Function
>
(
type
AsyncApi
<
T
extends
AsyncMethodOptionLike
>
=
AsyncApiOptionalOptions
extends
T
?
AsyncApiOptional
<
T
>
:
AsyncApiRequired
<
T
>
export
function
defineAsyncApi
<
T
extends
AsyncApiLike
,
P
=
AsyncApiOptions
<
T
>>
(
name
:
string
,
fn
:
T
,
fn
:
(
args
:
Omit
<
P
,
'
success
'
|
'
fail
'
|
'
complete
'
>
)
=>
Promise
<
AsyncApiRes
<
P
>
|
void
>
,
protocol
?:
ApiProtocols
,
options
?:
ApiOptions
)
{
return
promisify
(
defineApi
(
API_TYPE_ASYNC
,
name
,
fn
,
__DEV__
?
protocol
:
undefined
,
options
)
)
)
as
AsyncApi
<
P
>
}
function
defineApi
<
T
extends
Function
>
(
function
defineApi
(
type
:
API_TYPES
,
name
:
string
,
fn
:
T
,
fn
:
Function
,
protocol
?:
ApiProtocols
,
options
?:
ApiOptions
)
{
switch
(
type
)
{
case
API_TYPE_ON
:
return
wrapperApi
<
T
>
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
,
options
)
return
wrapperApi
(
wrapperOnApi
(
name
,
fn
),
name
,
protocol
,
options
)
case
API_TYPE_TASK
:
return
wrapperApi
<
T
>
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
,
options
)
return
wrapperApi
(
wrapperTaskApi
(
name
,
fn
),
name
,
protocol
,
options
)
case
API_TYPE_SYNC
:
return
wrapperApi
<
T
>
(
wrapperSyncApi
(
fn
),
name
,
protocol
,
options
)
return
wrapperApi
(
wrapperSyncApi
(
fn
),
name
,
protocol
,
options
)
case
API_TYPE_ASYNC
:
return
wrapperApi
<
T
>
(
wrapperAsyncApi
(
name
,
fn
,
options
),
return
wrapperApi
(
wrapperAsyncApi
(
name
,
fn
as
any
,
options
),
name
,
protocol
,
options
...
...
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
059d3dc4
...
...
@@ -7752,16 +7752,12 @@ function wrapperSyncApi(fn) {
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
res
=
fn
.
apply
(
null
,
[
args
,
(
res2
)
=>
{
invokeCallback
(
callbackId
,
res2
);
}
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
const
id2
=
createAsyncApiCallback
(
name
,
args
,
options
);
fn
(
args
).
then
((
res
)
=>
{
invokeCallback
(
id2
,
extend
(
res
||
{},
{
errMsg
:
name
+
"
:ok
"
}));
}).
catch
((
err
)
=>
{
invokeCallback
(
id2
,
{
errMsg
:
name
+
"
:fail
"
+
(
err
?
"
"
+
err
:
""
)});
});
};
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
...
...
@@ -8229,8 +8225,9 @@ const canIUse = defineSyncApi(API_CAN_I_USE, (schema) => {
}
return
true
;
},
CanIUseProtocol
);
const
makePhoneCall
=
defineAsyncApi
(
API_MAKE_PHONE_CALL
,
(
option
)
=>
{
window
.
location
.
href
=
`tel:
${
option
.
phoneNumber
}
`
;
const
makePhoneCall
=
defineAsyncApi
(
API_MAKE_PHONE_CALL
,
({
phoneNumber
})
=>
{
window
.
location
.
href
=
`tel:
${
phoneNumber
}
`
;
return
Promise
.
resolve
();
},
MakePhoneCallProtocol
);
const
getSystemInfoSync
=
defineSyncApi
(
"
getSystemInfoSync
"
,
()
=>
{
const
pixelRatio2
=
window
.
devicePixelRatio
;
...
...
@@ -8333,63 +8330,62 @@ const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => {
};
});
const
getSystemInfo
=
defineAsyncApi
(
"
getSystemInfo
"
,
()
=>
{
return
getSystemInfoSync
(
);
return
Promise
.
resolve
(
getSystemInfoSync
()
);
});
const
openDocument
=
defineAsyncApi
(
API_OPEN_DOCUMENT
,
(
option
)
=>
{
window
.
open
(
option
.
filePath
);
const
openDocument
=
defineAsyncApi
(
API_OPEN_DOCUMENT
,
({
filePath
})
=>
{
window
.
open
(
filePath
);
return
Promise
.
resolve
();
},
OpenDocumentProtocol
);
function
_getServiceAddress
()
{
return
window
.
location
.
protocol
+
"
//
"
+
window
.
location
.
host
;
}
const
getImageInfo
=
defineAsyncApi
(
API_GET_IMAGE_INFO
,
({
src
}
,
callback
)
=>
{
const
getImageInfo
=
defineAsyncApi
(
API_GET_IMAGE_INFO
,
({
src
})
=>
{
const
img
=
new
Image
();
img
.
onload
=
function
()
{
callback
({
errMsg
:
`
${
API_GET_IMAGE_INFO
}
:ok`
,
width
:
img
.
naturalWidth
,
height
:
img
.
naturalHeight
,
path
:
src
.
indexOf
(
"
/
"
)
===
0
?
_getServiceAddress
()
+
src
:
src
});
};
img
.
onerror
=
function
()
{
callback
({
errMsg
:
`
${
API_GET_IMAGE_INFO
}
:fail`
});
};
img
.
src
=
src
;
return
new
Promise
((
resolve
,
reject
)
=>
{
img
.
onload
=
function
()
{
resolve
({
width
:
img
.
naturalWidth
,
height
:
img
.
naturalHeight
,
path
:
src
.
indexOf
(
"
/
"
)
===
0
?
_getServiceAddress
()
+
src
:
src
});
};
img
.
onerror
=
function
()
{
reject
();
};
img
.
src
=
src
;
});
},
GetImageInfoProtocol
,
GetImageInfoOptions
);
const
navigateBack
=
defineAsyncApi
(
API_NAVIGATE_BACK
,
(
options
)
=>
{
const
navigateBack
=
defineAsyncApi
(
API_NAVIGATE_BACK
,
(
{
delta
})
=>
new
Promise
((
resolve
,
reject
)
=>
{
let
canBack
=
true
;
const
vm
=
getCurrentPageVm
();
if
(
vm
&&
vm
.
$callHook
(
"
onBackPress
"
)
===
true
)
{
canBack
=
false
;
}
if
(
!
canBack
)
{
return
{
errMsg
:
`
${
API_NAVIGATE_BACK
}
:fail onBackPress`
};
return
reject
(
"
onBackPress
"
);
}
getApp
().
$router
.
go
(
-
options
.
delta
);
},
NavigateBackProtocol
,
NavigateBackOptions
);
function
navigate
(
type
,
url
,
callback
)
{
getApp
().
$router
.
go
(
-
delta
);
resolve
();
}),
NavigateBackProtocol
,
NavigateBackOptions
);
function
navigate
(
type
,
url
)
{
const
router
=
getApp
().
$router
;
r
outer
[
type
===
"
navigateTo
"
?
"
push
"
:
"
replace
"
](
{
path
:
url
,
force
:
true
,
state
:
createPageState
(
type
)
}).
then
((
failure
)
=>
{
if
(
isNavigationFailure
(
failure
))
{
return
callback
(
{
errMsg
:
`:fail
${
failure
.
message
}
`
}
);
}
callback
(
);
r
eturn
new
Promise
((
resolve
,
reject
)
=>
{
router
[
type
===
"
navigateTo
"
?
"
push
"
:
"
replace
"
]({
path
:
url
,
force
:
true
,
state
:
createPageState
(
type
)
}).
then
((
failure
)
=>
{
if
(
isNavigationFailure
(
failure
))
{
return
reject
(
failure
.
message
);
}
return
resolve
();
}
);
});
}
const
navigateTo
=
defineAsyncApi
(
API_NAVIGATE_TO
,
(
options
,
callback
)
=>
navigate
(
API_NAVIGATE_TO
,
options
.
url
,
callback
),
NavigateToProtocol
,
NavigateToOptions
);
const
redirectTo
=
defineAsyncApi
(
API_REDIRECT_TO
,
(
options
,
callback
)
=>
navigate
(
API_REDIRECT_TO
,
options
.
url
,
callback
),
RedirectToProtocol
,
RedirectToOptions
);
const
reLaunch
=
defineAsyncApi
(
API_RE_LAUNCH
,
(
options
,
callback
)
=>
navigate
(
API_RE_LAUNCH
,
options
.
url
,
callback
),
ReLaunchProtocol
,
ReLaunchOptions
);
const
switchTab
=
defineAsyncApi
(
API_SWITCH_TAB
,
(
options
,
callback
)
=>
navigate
(
API_SWITCH_TAB
,
options
.
url
,
callback
),
SwitchTabProtocol
,
SwitchTabOptions
);
const
navigateTo
=
defineAsyncApi
(
API_NAVIGATE_TO
,
(
{
url
})
=>
navigate
(
API_NAVIGATE_TO
,
url
),
NavigateToProtocol
,
NavigateToOptions
);
const
redirectTo
=
defineAsyncApi
(
API_REDIRECT_TO
,
(
{
url
})
=>
navigate
(
API_REDIRECT_TO
,
url
),
RedirectToProtocol
,
RedirectToOptions
);
const
reLaunch
=
defineAsyncApi
(
API_RE_LAUNCH
,
(
{
url
})
=>
navigate
(
API_RE_LAUNCH
,
url
),
ReLaunchProtocol
,
ReLaunchOptions
);
const
switchTab
=
defineAsyncApi
(
API_SWITCH_TAB
,
(
{
url
})
=>
navigate
(
API_SWITCH_TAB
,
url
),
SwitchTabProtocol
,
SwitchTabOptions
);
var
api
=
/* @__PURE__ */
Object
.
freeze
({
__proto__
:
null
,
[
Symbol
.
toStringTag
]:
"
Module
"
,
...
...
packages/uni-h5/src/service/api/device/getSystemInfo.ts
浏览文件 @
059d3dc4
...
...
@@ -5,6 +5,6 @@ import { getSystemInfoSync } from './getSystemInfoSync'
export
const
getSystemInfo
=
defineAsyncApi
<
typeof
uni
.
getSystemInfo
>
(
'
getSystemInfo
'
,
()
=>
{
return
getSystemInfoSync
(
)
return
Promise
.
resolve
(
getSystemInfoSync
()
)
}
)
packages/uni-h5/src/service/api/device/makePhoneCall.ts
浏览文件 @
059d3dc4
...
...
@@ -6,8 +6,9 @@ import {
export
const
makePhoneCall
=
defineAsyncApi
<
typeof
uni
.
makePhoneCall
>
(
API_MAKE_PHONE_CALL
,
(
option
)
=>
{
window
.
location
.
href
=
`tel:
${
option
.
phoneNumber
}
`
({
phoneNumber
})
=>
{
window
.
location
.
href
=
`tel:
${
phoneNumber
}
`
return
Promise
.
resolve
()
},
MakePhoneCallProtocol
)
packages/uni-h5/src/service/api/file/openDocument.ts
浏览文件 @
059d3dc4
...
...
@@ -6,8 +6,9 @@ import {
export
const
openDocument
=
defineAsyncApi
<
typeof
uni
.
openDocument
>
(
API_OPEN_DOCUMENT
,
(
option
)
=>
{
window
.
open
(
option
.
filePath
)
({
filePath
})
=>
{
window
.
open
(
filePath
)
return
Promise
.
resolve
()
},
OpenDocumentProtocol
)
packages/uni-h5/src/service/api/media/getImageInfo.ts
浏览文件 @
059d3dc4
...
...
@@ -11,22 +11,21 @@ function _getServiceAddress() {
export
const
getImageInfo
=
defineAsyncApi
<
typeof
uni
.
getImageInfo
>
(
API_GET_IMAGE_INFO
,
({
src
}
,
callback
?:
Function
)
=>
{
({
src
})
=>
{
const
img
=
new
Image
()
img
.
onload
=
function
()
{
callback
!
({
errMsg
:
`
${
API_GET_IMAGE_INFO
}
:ok`
,
width
:
img
.
naturalWidth
,
height
:
img
.
naturalHeight
,
path
:
src
.
indexOf
(
'
/
'
)
===
0
?
_getServiceAddress
()
+
src
:
src
,
})
}
img
.
onerror
=
function
()
{
callback
!
({
errMsg
:
`
${
API_GET_IMAGE_INFO
}
:fail`
,
})
}
img
.
src
=
src
return
new
Promise
((
resolve
,
reject
)
=>
{
img
.
onload
=
function
()
{
resolve
({
width
:
img
.
naturalWidth
,
height
:
img
.
naturalHeight
,
path
:
src
.
indexOf
(
'
/
'
)
===
0
?
_getServiceAddress
()
+
src
:
src
,
}
as
UniApp
.
GetImageInfoSuccessData
)
// orientation和type是可选的,但GetImageInfoSuccessData定义的不对,暂时强制转换
}
img
.
onerror
=
function
()
{
reject
()
}
img
.
src
=
src
})
},
GetImageInfoProtocol
,
GetImageInfoOptions
...
...
packages/uni-h5/src/service/api/route/navigateBack.ts
浏览文件 @
059d3dc4
...
...
@@ -8,19 +8,19 @@ import {
export
const
navigateBack
=
defineAsyncApi
<
typeof
uni
.
navigateBack
>
(
API_NAVIGATE_BACK
,
(
options
)
=>
{
let
canBack
=
true
const
vm
=
getCurrentPageVm
()
if
(
vm
&&
vm
.
$callHook
(
'
onBackPress
'
)
===
true
)
{
canBack
=
false
}
if
(
!
canBack
)
{
return
{
errMsg
:
`
${
API_NAVIGATE_BACK
}
:fail onBackPress`
,
({
delta
})
=>
new
Promise
((
resolve
,
reject
)
=>
{
let
canBack
=
true
const
vm
=
getCurrentPageVm
()
if
(
vm
&&
vm
.
$callHook
(
'
onBackPress
'
)
===
true
)
{
canBack
=
false
}
}
getApp
().
$router
.
go
(
-
options
.
delta
!
)
},
if
(
!
canBack
)
{
return
reject
(
'
onBackPress
'
)
}
getApp
().
$router
.
go
(
-
delta
!
)
resolve
()
}),
NavigateBackProtocol
,
NavigateBackOptions
)
packages/uni-h5/src/service/api/route/navigateTo.ts
浏览文件 @
059d3dc4
...
...
@@ -8,8 +8,7 @@ import { navigate } from './utils'
export
const
navigateTo
=
defineAsyncApi
<
typeof
uni
.
navigateTo
>
(
API_NAVIGATE_TO
,
(
options
,
callback
?:
Function
)
=>
navigate
(
API_NAVIGATE_TO
,
options
.
url
,
callback
!
),
({
url
})
=>
navigate
(
API_NAVIGATE_TO
,
url
),
NavigateToProtocol
,
NavigateToOptions
)
packages/uni-h5/src/service/api/route/reLaunch.ts
浏览文件 @
059d3dc4
...
...
@@ -8,8 +8,7 @@ import { navigate } from './utils'
export
const
reLaunch
=
defineAsyncApi
<
typeof
uni
.
reLaunch
>
(
API_RE_LAUNCH
,
(
options
,
callback
?:
Function
)
=>
navigate
(
API_RE_LAUNCH
,
options
.
url
,
callback
!
),
({
url
})
=>
navigate
(
API_RE_LAUNCH
,
url
),
ReLaunchProtocol
,
ReLaunchOptions
)
packages/uni-h5/src/service/api/route/redirectTo.ts
浏览文件 @
059d3dc4
...
...
@@ -8,8 +8,7 @@ import { navigate } from './utils'
export
const
redirectTo
=
defineAsyncApi
<
typeof
uni
.
redirectTo
>
(
API_REDIRECT_TO
,
(
options
,
callback
?:
Function
)
=>
navigate
(
API_REDIRECT_TO
,
options
.
url
,
callback
!
),
({
url
})
=>
navigate
(
API_REDIRECT_TO
,
url
),
RedirectToProtocol
,
RedirectToOptions
)
packages/uni-h5/src/service/api/route/switchTab.ts
浏览文件 @
059d3dc4
...
...
@@ -8,8 +8,7 @@ import { navigate } from './utils'
export
const
switchTab
=
defineAsyncApi
<
typeof
uni
.
switchTab
>
(
API_SWITCH_TAB
,
(
options
,
callback
?:
Function
)
=>
navigate
(
API_SWITCH_TAB
,
options
.
url
,
callback
!
),
({
url
})
=>
navigate
(
API_SWITCH_TAB
,
url
),
SwitchTabProtocol
,
SwitchTabOptions
)
packages/uni-h5/src/service/api/route/utils.ts
浏览文件 @
059d3dc4
...
...
@@ -3,20 +3,19 @@ import { createPageState } from '../../../framework/plugin/page'
export
function
navigate
(
type
:
'
navigateTo
'
|
'
redirectTo
'
|
'
reLaunch
'
|
'
switchTab
'
,
url
:
string
,
callback
:
Function
)
{
url
:
string
):
Promise
<
void
>
{
const
router
=
getApp
().
$router
as
Router
r
outer
[
type
===
'
navigateTo
'
?
'
push
'
:
'
replace
'
](
{
path
:
url
,
force
:
true
,
state
:
createPageState
(
type
)
,
}).
then
((
failure
)
=>
{
if
(
isNavigationFailure
(
failure
))
{
return
callback
(
{
errMsg
:
`:fail
${
failure
.
message
}
`
,
}
)
}
callback
(
)
r
eturn
new
Promise
((
resolve
,
reject
)
=>
{
router
[
type
===
'
navigateTo
'
?
'
push
'
:
'
replace
'
]({
path
:
url
,
force
:
true
,
state
:
createPageState
(
type
),
}).
then
((
failure
)
=>
{
if
(
isNavigationFailure
(
failure
))
{
return
reject
(
failure
.
message
)
}
return
resolve
()
}
)
})
}
packages/uni-mp-alipay/dist/uni.api.esm.js
浏览文件 @
059d3dc4
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
extend
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
function
validateProtocolFail
(
name
,
msg
)
{
const
errMsg
=
`
${
name
}
:fail
${
msg
}
`
;
...
...
@@ -276,16 +276,14 @@ function wrapperSyncApi(fn) {
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
res
=
fn
.
apply
(
null
,
[
args
,
(
res
)
=>
{
invokeCallback
(
callbackId
,
res
);
},
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
fn
(
args
)
.
then
((
res
)
=>
{
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
})
.
catch
((
err
)
=>
{
invokeCallback
(
id
,
{
errMsg
:
name
+
'
:fail
'
+
(
err
?
'
'
+
err
:
''
)
});
});
};
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
...
...
packages/uni-mp-baidu/dist/uni.api.esm.js
浏览文件 @
059d3dc4
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
extend
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
function
validateProtocolFail
(
name
,
msg
)
{
const
errMsg
=
`
${
name
}
:fail
${
msg
}
`
;
...
...
@@ -276,16 +276,14 @@ function wrapperSyncApi(fn) {
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
res
=
fn
.
apply
(
null
,
[
args
,
(
res
)
=>
{
invokeCallback
(
callbackId
,
res
);
},
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
fn
(
args
)
.
then
((
res
)
=>
{
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
})
.
catch
((
err
)
=>
{
invokeCallback
(
id
,
{
errMsg
:
name
+
'
:fail
'
+
(
err
?
'
'
+
err
:
''
)
});
});
};
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
...
...
packages/uni-mp-qq/dist/uni.api.esm.js
浏览文件 @
059d3dc4
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
extend
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
function
validateProtocolFail
(
name
,
msg
)
{
const
errMsg
=
`
${
name
}
:fail
${
msg
}
`
;
...
...
@@ -276,16 +276,14 @@ function wrapperSyncApi(fn) {
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
res
=
fn
.
apply
(
null
,
[
args
,
(
res
)
=>
{
invokeCallback
(
callbackId
,
res
);
},
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
fn
(
args
)
.
then
((
res
)
=>
{
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
})
.
catch
((
err
)
=>
{
invokeCallback
(
id
,
{
errMsg
:
name
+
'
:fail
'
+
(
err
?
'
'
+
err
:
''
)
});
});
};
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
...
...
packages/uni-mp-toutiao/dist/uni.api.esm.js
浏览文件 @
059d3dc4
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
extend
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
function
validateProtocolFail
(
name
,
msg
)
{
const
errMsg
=
`
${
name
}
:fail
${
msg
}
`
;
...
...
@@ -276,16 +276,14 @@ function wrapperSyncApi(fn) {
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
res
=
fn
.
apply
(
null
,
[
args
,
(
res
)
=>
{
invokeCallback
(
callbackId
,
res
);
},
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
fn
(
args
)
.
then
((
res
)
=>
{
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
})
.
catch
((
err
)
=>
{
invokeCallback
(
id
,
{
errMsg
:
name
+
'
:fail
'
+
(
err
?
'
'
+
err
:
''
)
});
});
};
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
...
...
packages/uni-mp-weixin/dist/uni.api.esm.js
浏览文件 @
059d3dc4
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
extend
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
function
validateProtocolFail
(
name
,
msg
)
{
const
errMsg
=
`
${
name
}
:fail
${
msg
}
`
;
...
...
@@ -276,16 +276,14 @@ function wrapperSyncApi(fn) {
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
res
=
fn
.
apply
(
null
,
[
args
,
(
res
)
=>
{
invokeCallback
(
callbackId
,
res
);
},
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
fn
(
args
)
.
then
((
res
)
=>
{
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
})
.
catch
((
err
)
=>
{
invokeCallback
(
id
,
{
errMsg
:
name
+
'
:fail
'
+
(
err
?
'
'
+
err
:
''
)
});
});
};
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
...
...
packages/uni-quickapp-webview/dist/uni.api.esm.js
浏览文件 @
059d3dc4
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isPlainObject
,
isFunction
,
extend
,
isPromise
,
isString
}
from
'
@vue/shared
'
;
function
validateProtocolFail
(
name
,
msg
)
{
const
errMsg
=
`
${
name
}
:fail
${
msg
}
`
;
...
...
@@ -276,16 +276,14 @@ function wrapperSyncApi(fn) {
}
function
wrapperAsyncApi
(
name
,
fn
,
options
)
{
return
(
args
)
=>
{
const
callbackId
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
res
=
fn
.
apply
(
null
,
[
args
,
(
res
)
=>
{
invokeCallback
(
callbackId
,
res
);
},
]);
if
(
res
)
{
invokeCallback
(
callbackId
,
res
);
}
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
fn
(
args
)
.
then
((
res
)
=>
{
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
})
.
catch
((
err
)
=>
{
invokeCallback
(
id
,
{
errMsg
:
name
+
'
:fail
'
+
(
err
?
'
'
+
err
:
''
)
});
});
};
}
function
wrapperApi
(
fn
,
name
,
protocol
,
options
)
{
...
...
packages/vite-plugin-uni/src/utils/define.ts
浏览文件 @
059d3dc4
...
...
@@ -145,7 +145,7 @@ function resolveManifestFeature(
options
:
VitePluginUniResolvedOptions
):
ManifestFeatures
{
const
features
:
ManifestFeatures
=
{
wx
:
true
,
// 是否启用小程序的组件实例 API,如:selectComponent 等(uni-core/src/service/plugin/appConfig)
wx
:
true
,
wxs
:
true
,
// 是否启用 wxs 支持,如:getComponentDescriptor 等(uni-core/src/view/plugin/appConfig)
promise
:
false
,
// 是否启用旧版本的 promise 支持(即返回[err,res]的格式)
longpress
:
true
,
// 是否启用longpress
...
...
@@ -194,22 +194,23 @@ export function getFeatures(
resolveProjectFeature
(
options
,
command
)
)
return
{
__UNI_FEATURE_WX__
:
wx
,
__UNI_FEATURE_WXS__
:
wxs
,
__UNI_FEATURE_NVUE__
:
nvue
,
__UNI_FEATURE_PROMISE__
:
promise
,
__UNI_FEATURE_LONGPRESS__
:
longpress
,
__UNI_FEATURE_ROUTER_MODE__
:
routerMode
,
__UNI_FEATURE_PAGES__
:
pages
,
__UNI_FEATURE_TABBAR__
:
tabBar
,
__UNI_FEATURE_TOPWINDOW__
:
topWindow
,
__UNI_FEATURE_LEFTWINDOW__
:
leftWindow
,
__UNI_FEATURE_RIGHTWINDOW__
:
rightWindow
,
__UNI_FEATURE_RESPONSIVE__
:
topWindow
||
leftWindow
||
rightWindow
,
__UNI_FEATURE_NAVIGATIONBAR__
:
navigationBar
,
__UNI_FEATURE_PULL_DOWN_REFRESH__
:
pullDownRefresh
,
__UNI_FEATURE_NAVIGATIONBAR_BUTTONS__
:
navigationBarButtons
,
__UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__
:
navigationBarSearchInput
,
__UNI_FEATURE_NAVIGATIONBAR_TRANSPARENT__
:
navigationBarTransparent
,
__UNI_FEATURE_WX__
:
wx
,
// 是否启用小程序的组件实例 API,如:selectComponent 等(uni-core/src/service/plugin/appConfig)
__UNI_FEATURE_WXS__
:
wxs
,
// 是否启用 wxs 支持,如:getComponentDescriptor 等(uni-core/src/view/plugin/appConfig)
__UNI_FEATURE_PROMISE__
:
promise
,
// 是否启用旧版本的 promise 支持(即返回[err,res]的格式),默认返回标准
__UNI_FEATURE_LONGPRESS__
:
longpress
,
// 是否启用longpress
// 以下特性,编译器已自动识别是否需要启用
__UNI_FEATURE_NVUE__
:
nvue
,
// 是否启用nvue
__UNI_FEATURE_ROUTER_MODE__
:
routerMode
,
// 路由模式
__UNI_FEATURE_PAGES__
:
pages
,
// 是否多页面
__UNI_FEATURE_TABBAR__
:
tabBar
,
// 是否包含tabBar
__UNI_FEATURE_TOPWINDOW__
:
topWindow
,
// 是否包含topWindow
__UNI_FEATURE_LEFTWINDOW__
:
leftWindow
,
// 是否包含leftWindow
__UNI_FEATURE_RIGHTWINDOW__
:
rightWindow
,
// 是否包含rightWindow
__UNI_FEATURE_RESPONSIVE__
:
topWindow
||
leftWindow
||
rightWindow
,
// 是否启用响应式
__UNI_FEATURE_NAVIGATIONBAR__
:
navigationBar
,
// 是否启用标题栏
__UNI_FEATURE_PULL_DOWN_REFRESH__
:
pullDownRefresh
,
// 是否启用下拉刷新
__UNI_FEATURE_NAVIGATIONBAR_BUTTONS__
:
navigationBarButtons
,
// 是否启用标题栏按钮
__UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__
:
navigationBarSearchInput
,
// 是否启用标题栏搜索框
__UNI_FEATURE_NAVIGATIONBAR_TRANSPARENT__
:
navigationBarTransparent
,
// 是否启用透明标题栏
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录