Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzb_79
uni-app
提交
1c035f7e
U
uni-app
项目概览
lzb_79
/
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,发现更多精彩内容 >>
提交
1c035f7e
编写于
9月 15, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(api): createApi
上级
d92b46a9
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
229 addition
and
45 deletion
+229
-45
packages/uni-api/src/helpers/api.ts
packages/uni-api/src/helpers/api.ts
+1
-1
packages/uni-api/src/index.ts
packages/uni-api/src/index.ts
+0
-1
packages/uni-api/src/service/base/base64.ts
packages/uni-api/src/service/base/base64.ts
+12
-6
packages/uni-api/src/service/base/upx2px.ts
packages/uni-api/src/service/base/upx2px.ts
+2
-2
packages/uni-api/src/service/ui/createIntersectionObserver.ts
...ages/uni-api/src/service/ui/createIntersectionObserver.ts
+126
-1
packages/uni-api/src/service/ui/createSelectorQuery.ts
packages/uni-api/src/service/ui/createSelectorQuery.ts
+0
-3
packages/uni-api/src/service/utils.ts
packages/uni-api/src/service/utils.ts
+6
-0
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+72
-10
packages/uni-h5/src/service/api/base/canIUse.ts
packages/uni-h5/src/service/api/base/canIUse.ts
+1
-1
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/getSystemInfoSync.ts
packages/uni-h5/src/service/api/device/getSystemInfoSync.ts
+2
-2
packages/uni-h5/src/service/api/device/makePhoneCall.ts
packages/uni-h5/src/service/api/device/makePhoneCall.ts
+3
-9
packages/uni-h5/src/service/api/file/openDocument.ts
packages/uni-h5/src/service/api/file/openDocument.ts
+1
-5
packages/uni-h5/src/service/api/index.ts
packages/uni-h5/src/service/api/index.ts
+0
-1
packages/uni-h5/src/service/api/route/navigateBack.ts
packages/uni-h5/src/service/api/route/navigateBack.ts
+1
-1
packages/uni-h5/src/service/api/route/navigateTo.ts
packages/uni-h5/src/service/api/route/navigateTo.ts
+1
-1
未找到文件。
packages/uni-api/src/helpers/api.ts
浏览文件 @
1c035f7e
import
{
ProtocolOptions
}
from
'
../protocols/type
'
export
function
createApi
<
T
extends
Function
=
()
=>
any
>
(
export
function
createApi
<
T
extends
Function
>
(
fn
:
T
,
validate
?:
ProtocolOptions
|
ProtocolOptions
[]
)
{
...
...
packages/uni-api/src/index.ts
浏览文件 @
1c035f7e
...
...
@@ -3,7 +3,6 @@ export * from './service/base/upx2px'
export
*
from
'
./service/base/interceptor
'
export
*
from
'
./service/ui/createIntersectionObserver
'
export
*
from
'
./service/ui/createSelectorQuery
'
// protocols
export
*
from
'
./protocols/base/canIUse
'
...
...
packages/uni-api/src/service/base/base64.ts
浏览文件 @
1c035f7e
...
...
@@ -8,10 +8,16 @@ import {
ArrayBufferToBase64Protocol
}
from
'
../../protocols/base/base64
'
export
const
base64ToArrayBuffer
=
createApi
((
base64
:
string
)
=>
{
return
decode
(
base64
)
as
ArrayBuffer
},
Base64ToArrayBufferProtocol
)
export
const
base64ToArrayBuffer
=
createApi
<
typeof
uni
.
base64ToArrayBuffer
>
(
base64
=>
{
return
decode
(
base64
)
as
ArrayBuffer
},
Base64ToArrayBufferProtocol
)
export
const
arrayBufferToBase64
=
createApi
((
arrayBuffer
:
ArrayBuffer
)
=>
{
return
encode
(
arrayBuffer
)
as
string
},
ArrayBufferToBase64Protocol
)
export
const
arrayBufferToBase64
=
createApi
<
typeof
uni
.
arrayBufferToBase64
>
(
arrayBuffer
=>
{
return
encode
(
arrayBuffer
)
as
string
},
ArrayBufferToBase64Protocol
)
packages/uni-api/src/service/base/upx2px.ts
浏览文件 @
1c035f7e
...
...
@@ -14,8 +14,8 @@ function checkDeviceWidth() {
isIOS
=
platform
===
'
ios
'
}
export
const
upx2px
=
createApi
(
(
number
:
number
,
newDeviceWidth
:
number
|
undefined
)
=>
{
export
const
upx2px
=
createApi
<
typeof
uni
.
upx2px
>
(
(
number
,
newDeviceWidth
?:
number
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
()
}
...
...
packages/uni-api/src/service/ui/createIntersectionObserver.ts
浏览文件 @
1c035f7e
import
{
extend
}
from
'
@vue/shared
'
import
{
createApi
}
from
'
../../helpers/api
'
import
{
getCurrentPageVm
}
from
'
../utils
'
const
defaultOptions
=
{
thresholds
:
[
0
],
initialRatio
:
0
,
observeAll
:
false
}
interface
Margins
{
bottom
?:
number
left
?:
number
right
?:
number
top
?:
number
}
interface
RelativeInfo
{
selector
:
string
margins
:
Margins
}
type
ObserveResultCallback
=
(
result
:
UniApp
.
ObserveResult
)
=>
void
interface
requestComponentObserver
{
reqId
:
number
reqEnd
:
boolean
res
:
UniApp
.
ObserveResult
}
let
reqComponentObserverId
=
1
const
reqComponentObserverCallbacks
:
Record
<
number
,
ObserveResultCallback
>
=
{}
UniServiceJSBridge
.
subscribe
(
'
requestComponentObserver
'
,
({
reqId
,
reqEnd
,
res
}:
requestComponentObserver
)
=>
{
const
callback
=
reqComponentObserverCallbacks
[
reqId
]
if
(
callback
)
{
if
(
reqEnd
)
{
return
delete
reqComponentObserverCallbacks
[
reqId
]
}
callback
(
res
)
}
}
)
class
ServiceIntersectionObserver
{
private
_reqId
?:
number
private
_options
:
UniApp
.
CreateIntersectionObserverOptions
private
_component
:
any
private
_pageId
:
number
private
_relativeInfo
:
RelativeInfo
[]
constructor
(
component
:
any
,
options
:
UniApp
.
CreateIntersectionObserverOptions
)
{
this
.
_pageId
=
component
.
$page
.
id
this
.
_component
=
component
.
_$id
||
component
// app-plus 平台传输_$id
this
.
_options
=
extend
({},
defaultOptions
,
options
||
{})
this
.
_relativeInfo
=
[]
}
relativeTo
(
selector
:
string
,
margins
:
Margins
)
{
if
(
this
.
_reqId
)
{
throw
new
Error
(
'
Relative nodes cannot be added after "observe" call in IntersectionObserver
'
)
}
this
.
_relativeInfo
.
push
({
selector
,
margins
})
return
this
}
relativeToViewport
(
margins
:
Margins
)
{
return
this
.
relativeTo
((
null
as
unknown
)
as
string
,
margins
)
}
observe
(
selector
:
string
,
callback
:
ObserveResultCallback
)
{
if
(
typeof
callback
!==
'
function
'
)
{
return
}
if
(
this
.
_reqId
)
{
throw
new
Error
(
'
"observe" call can be only called once in IntersectionObserver
'
)
}
this
.
_reqId
=
reqComponentObserverId
++
reqComponentObserverCallbacks
[
this
.
_reqId
]
=
callback
UniServiceJSBridge
.
publishHandler
(
'
addIntersectionObserver
'
,
{
selector
,
reqId
:
this
.
_reqId
,
component
:
this
.
_component
,
options
:
this
.
_options
,
relativeInfo
:
this
.
_relativeInfo
},
this
.
_pageId
)
}
disconnect
()
{
UniServiceJSBridge
.
publishHandler
(
'
removeIntersectionObserver
'
,
{
reqId
:
this
.
_reqId
},
this
.
_pageId
)
}
}
export
const
createIntersectionObserver
=
createApi
(()
=>
{})
export
const
createIntersectionObserver
=
createApi
<
typeof
uni
.
createIntersectionObserver
>
((
context
?,
options
?)
=>
{
if
(
!
context
)
{
context
=
getCurrentPageVm
()
}
return
new
ServiceIntersectionObserver
(
context
,
options
)
})
packages/uni-api/src/service/ui/createSelectorQuery.ts
已删除
100644 → 0
浏览文件 @
d92b46a9
import
{
createApi
}
from
'
../../helpers/api
'
export
const
createSelectorQuery
=
createApi
(()
=>
{})
packages/uni-api/src/service/utils.ts
0 → 100644
浏览文件 @
1c035f7e
export
function
getCurrentPageVm
()
{
const
pages
=
getCurrentPages
()
const
len
=
pages
.
length
const
page
=
pages
[
len
-
1
]
return
page
&&
(
page
as
any
).
$vm
}
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
1c035f7e
...
...
@@ -1414,9 +1414,76 @@ const promiseInterceptor = {
});
}
};
const
createIntersectionObserver$1
=
/* @__PURE__ */
createApi
(()
=>
{
function
getCurrentPageVm
()
{
const
pages
=
getCurrentPages
();
const
len
=
pages
.
length
;
const
page
=
pages
[
len
-
1
];
return
page
&&
page
.
$vm
;
}
const
defaultOptions
=
{
thresholds
:
[
0
],
initialRatio
:
0
,
observeAll
:
false
};
let
reqComponentObserverId
=
1
;
const
reqComponentObserverCallbacks
=
{};
UniServiceJSBridge
.
subscribe
(
"
requestComponentObserver
"
,
({
reqId
,
reqEnd
,
res
})
=>
{
const
callback
=
reqComponentObserverCallbacks
[
reqId
];
if
(
callback
)
{
if
(
reqEnd
)
{
return
delete
reqComponentObserverCallbacks
[
reqId
];
}
callback
(
res
);
}
});
const
createSelectorQuery$1
=
/* @__PURE__ */
createApi
(()
=>
{
class
ServiceIntersectionObserver
{
constructor
(
component
,
options
)
{
this
.
_pageId
=
component
.
$page
.
id
;
this
.
_component
=
component
.
_$id
||
component
;
this
.
_options
=
extend
({},
defaultOptions
,
options
||
{});
this
.
_relativeInfo
=
[];
}
relativeTo
(
selector
,
margins
)
{
if
(
this
.
_reqId
)
{
throw
new
Error
(
'
Relative nodes cannot be added after "observe" call in IntersectionObserver
'
);
}
this
.
_relativeInfo
.
push
({
selector
,
margins
});
return
this
;
}
relativeToViewport
(
margins
)
{
return
this
.
relativeTo
(
null
,
margins
);
}
observe
(
selector
,
callback
)
{
if
(
typeof
callback
!==
"
function
"
)
{
return
;
}
if
(
this
.
_reqId
)
{
throw
new
Error
(
'
"observe" call can be only called once in IntersectionObserver
'
);
}
this
.
_reqId
=
reqComponentObserverId
++
;
reqComponentObserverCallbacks
[
this
.
_reqId
]
=
callback
;
UniServiceJSBridge
.
publishHandler
(
"
addIntersectionObserver
"
,
{
selector
,
reqId
:
this
.
_reqId
,
component
:
this
.
_component
,
options
:
this
.
_options
,
relativeInfo
:
this
.
_relativeInfo
},
this
.
_pageId
);
}
disconnect
()
{
UniServiceJSBridge
.
publishHandler
(
"
removeIntersectionObserver
"
,
{
reqId
:
this
.
_reqId
},
this
.
_pageId
);
}
}
const
createIntersectionObserver$1
=
/* @__PURE__ */
createApi
((
context
,
options
)
=>
{
if
(
!
context
)
{
context
=
getCurrentPageVm
();
}
return
new
ServiceIntersectionObserver
(
context
,
options
);
});
const
CanIUseProtocol
=
[
{
...
...
@@ -1459,11 +1526,8 @@ const canIUse = /* @__PURE__ */ createApi((schema) => {
}
return
true
;
},
CanIUseProtocol
);
const
makePhoneCall
=
/* @__PURE__ */
createApi
(({
phoneNumber
})
=>
{
window
.
location
.
href
=
`tel:
${
phoneNumber
}
`
;
return
{
errMsg
:
"
makePhoneCall:ok
"
};
const
makePhoneCall
=
/* @__PURE__ */
createApi
((
option
)
=>
{
window
.
location
.
href
=
`tel:
${
option
.
phoneNumber
}
`
;
},
MakePhoneCallProtocol
);
const
ua
=
navigator
.
userAgent
;
const
isAndroid
=
/android/i
.
test
(
ua
);
...
...
@@ -1574,7 +1638,6 @@ const getSystemInfo = /* @__PURE__ */ createApi(() => {
});
const
openDocument
=
/* @__PURE__ */
createApi
((
option
)
=>
{
window
.
open
(
option
.
filePath
);
return
true
;
},
OpenDocumentProtocol
);
const
navigateBack
=
/* @__PURE__ */
createApi
(()
=>
{
});
...
...
@@ -1594,7 +1657,6 @@ var api = /* @__PURE__ */ Object.freeze({
promiseInterceptor
,
arrayBufferToBase64
,
base64ToArrayBuffer
,
createSelectorQuery
:
createSelectorQuery$1
,
createIntersectionObserver
:
createIntersectionObserver$1
,
canIUse
,
makePhoneCall
,
...
...
@@ -2730,4 +2792,4 @@ function render$a(_ctx, _cache, $props, $setup, $data, $options) {
;
script$a
.
render
=
render$a
;
script$a
.
__file
=
"
packages/uni-h5/src/framework/components/async-loading/index.vue
"
;
export
{
script$9
as
AsyncErrorComponent
,
script$a
as
AsyncLoadingComponent
,
script$8
as
PageComponent
,
addInterceptor
,
arrayBufferToBase64
,
base64ToArrayBuffer
,
canIUse
,
createIntersectionObserver$1
as
createIntersectionObserver
,
createSelectorQuery$1
as
createSelectorQuery
,
getApp
,
getCurrentPages$1
as
getCurrentPages
,
getSystemInfo
,
getSystemInfoSync
,
makePhoneCall
,
navigateBack
,
navigateTo
,
openDocument
,
index
as
plugin
,
promiseInterceptor
,
reLaunch
,
redirectTo
,
removeInterceptor
,
switchTab
,
uni$1
as
uni
,
upx2px
};
export
{
script$9
as
AsyncErrorComponent
,
script$a
as
AsyncLoadingComponent
,
script$8
as
PageComponent
,
addInterceptor
,
arrayBufferToBase64
,
base64ToArrayBuffer
,
canIUse
,
createIntersectionObserver$1
as
createIntersectionObserver
,
getApp
,
getCurrentPages$1
as
getCurrentPages
,
getSystemInfo
,
getSystemInfoSync
,
makePhoneCall
,
navigateBack
,
navigateTo
,
openDocument
,
index
as
plugin
,
promiseInterceptor
,
reLaunch
,
redirectTo
,
removeInterceptor
,
switchTab
,
uni$1
as
uni
,
upx2px
};
packages/uni-h5/src/service/api/base/canIUse.ts
浏览文件 @
1c035f7e
...
...
@@ -12,7 +12,7 @@ const SCHEMA_CSS = {
'
css.constant
'
:
cssSupports
(
'
top:constant(a)
'
)
}
export
const
canIUse
=
createApi
((
schema
:
string
)
=>
{
export
const
canIUse
=
createApi
<
typeof
uni
.
canIUse
>
((
schema
:
string
)
=>
{
if
(
hasOwn
(
SCHEMA_CSS
,
schema
))
{
return
SCHEMA_CSS
[
schema
]
}
...
...
packages/uni-h5/src/service/api/device/getSystemInfo.ts
浏览文件 @
1c035f7e
...
...
@@ -2,6 +2,6 @@ import { createApi } from '@dcloudio/uni-api'
import
{
getSystemInfoSync
}
from
'
./getSystemInfoSync
'
export
const
getSystemInfo
=
createApi
(()
=>
{
export
const
getSystemInfo
=
createApi
<
typeof
uni
.
getSystemInfo
>
(()
=>
{
return
getSystemInfoSync
()
})
packages/uni-h5/src/service/api/device/getSystemInfoSync.ts
浏览文件 @
1c035f7e
...
...
@@ -16,7 +16,7 @@ const isIOS = /iphone|ipad|ipod/i.test(ua)
/**
* 获取系统信息-同步
*/
export
const
getSystemInfoSync
=
createApi
(()
=>
{
export
const
getSystemInfoSync
=
createApi
<
typeof
uni
.
getSystemInfoSync
>
(()
=>
{
var
screen
=
window
.
screen
var
pixelRatio
=
window
.
devicePixelRatio
// 横屏时 iOS 获取的屏幕宽高颠倒,进行纠正
...
...
@@ -133,5 +133,5 @@ export const getSystemInfoSync = createApi(() => {
bottom
:
safeAreaInsets
.
bottom
,
left
:
safeAreaInsets
.
left
}
}
}
as
UniApp
.
GetSystemInfoResult
})
packages/uni-h5/src/service/api/device/makePhoneCall.ts
浏览文件 @
1c035f7e
import
{
createApi
,
MakePhoneCallProtocol
}
from
'
@dcloudio/uni-api
'
export
const
makePhoneCall
=
createApi
(
({
phoneNumber
}:
{
phoneNumber
:
string
})
=>
{
window
.
location
.
href
=
`tel:
${
phoneNumber
}
`
return
{
errMsg
:
'
makePhoneCall:ok
'
}
},
MakePhoneCallProtocol
)
export
const
makePhoneCall
=
createApi
<
typeof
uni
.
makePhoneCall
>
(
option
=>
{
window
.
location
.
href
=
`tel:
${
option
.
phoneNumber
}
`
},
MakePhoneCallProtocol
)
packages/uni-h5/src/service/api/file/openDocument.ts
浏览文件 @
1c035f7e
import
{
createApi
,
OpenDocumentProtocol
}
from
'
@dcloudio/uni-api
'
interface
OpenDocumentOption
{
filePath
:
string
}
export
const
openDocument
=
createApi
((
option
:
OpenDocumentOption
)
=>
{
export
const
openDocument
=
createApi
<
typeof
uni
.
openDocument
>
(
option
=>
{
window
.
open
(
option
.
filePath
)
return
true
},
OpenDocumentProtocol
)
packages/uni-h5/src/service/api/index.ts
浏览文件 @
1c035f7e
...
...
@@ -19,6 +19,5 @@ export {
promiseInterceptor
,
arrayBufferToBase64
,
base64ToArrayBuffer
,
createSelectorQuery
,
createIntersectionObserver
}
from
'
@dcloudio/uni-api
'
packages/uni-h5/src/service/api/route/navigateBack.ts
浏览文件 @
1c035f7e
import
{
createApi
}
from
'
@dcloudio/uni-api
'
export
const
navigateBack
=
createApi
(()
=>
{})
export
const
navigateBack
=
createApi
<
typeof
uni
.
navigateBack
>
(()
=>
{})
packages/uni-h5/src/service/api/route/navigateTo.ts
浏览文件 @
1c035f7e
import
{
createApi
}
from
'
@dcloudio/uni-api
'
export
const
navigateTo
=
createApi
(()
=>
{})
export
const
navigateTo
=
createApi
<
typeof
uni
.
navigateTo
>
(()
=>
{})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录