Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
415b832d
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,发现更多精彩内容 >>
提交
415b832d
编写于
9月 16, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: createApi
上级
ea5795ec
变更
27
隐藏空白更改
内联
并排
Showing
27 changed file
with
418 addition
and
237 deletion
+418
-237
packages/uni-api/src/helpers/api.ts
packages/uni-api/src/helpers/api.ts
+38
-7
packages/uni-api/src/index.ts
packages/uni-api/src/index.ts
+8
-1
packages/uni-api/src/service/base/base64.ts
packages/uni-api/src/service/base/base64.ts
+3
-1
packages/uni-api/src/service/base/interceptor.ts
packages/uni-api/src/service/base/interceptor.ts
+3
-1
packages/uni-api/src/service/base/upx2px.ts
packages/uni-api/src/service/base/upx2px.ts
+2
-1
packages/uni-api/src/service/ui/createIntersectionObserver.ts
...ages/uni-api/src/service/ui/createIntersectionObserver.ts
+2
-2
packages/uni-api/src/service/ui/createSelectorQuery.ts
packages/uni-api/src/service/ui/createSelectorQuery.ts
+1
-0
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+45
-30
packages/uni-h5/src/service/api/base/canIUse.ts
packages/uni-h5/src/service/api/base/canIUse.ts
+11
-7
packages/uni-h5/src/service/api/device/getSystemInfo.ts
packages/uni-h5/src/service/api/device/getSystemInfo.ts
+7
-4
packages/uni-h5/src/service/api/device/getSystemInfoSync.ts
packages/uni-h5/src/service/api/device/getSystemInfoSync.ts
+113
-110
packages/uni-h5/src/service/api/device/makePhoneCall.ts
packages/uni-h5/src/service/api/device/makePhoneCall.ts
+12
-4
packages/uni-h5/src/service/api/file/openDocument.ts
packages/uni-h5/src/service/api/file/openDocument.ts
+12
-4
packages/uni-h5/src/service/api/index.ts
packages/uni-h5/src/service/api/index.ts
+2
-1
packages/uni-h5/src/service/api/media/getImageInfo.ts
packages/uni-h5/src/service/api/media/getImageInfo.ts
+7
-11
packages/uni-h5/src/service/api/route/navigateBack.ts
packages/uni-h5/src/service/api/route/navigateBack.ts
+5
-2
packages/uni-h5/src/service/api/route/navigateTo.ts
packages/uni-h5/src/service/api/route/navigateTo.ts
+8
-5
packages/uni-h5/src/service/api/route/reLaunch.ts
packages/uni-h5/src/service/api/route/reLaunch.ts
+2
-2
packages/uni-h5/src/service/api/route/redirectTo.ts
packages/uni-h5/src/service/api/route/redirectTo.ts
+2
-2
packages/uni-h5/src/service/api/route/switchTab.ts
packages/uni-h5/src/service/api/route/switchTab.ts
+2
-2
packages/uni-h5/src/service/api/util/getRealPath.ts
packages/uni-h5/src/service/api/util/getRealPath.ts
+7
-4
packages/uni-mp-alipay/dist/uni.api.esm.js
packages/uni-mp-alipay/dist/uni.api.esm.js
+21
-6
packages/uni-mp-baidu/dist/uni.api.esm.js
packages/uni-mp-baidu/dist/uni.api.esm.js
+21
-6
packages/uni-mp-qq/dist/uni.api.esm.js
packages/uni-mp-qq/dist/uni.api.esm.js
+21
-6
packages/uni-mp-toutiao/dist/uni.api.esm.js
packages/uni-mp-toutiao/dist/uni.api.esm.js
+21
-6
packages/uni-mp-weixin/dist/uni.api.esm.js
packages/uni-mp-weixin/dist/uni.api.esm.js
+21
-6
packages/uni-quickapp-webview/dist/uni.api.esm.js
packages/uni-quickapp-webview/dist/uni.api.esm.js
+21
-6
未找到文件。
packages/uni-api/src/helpers/api.ts
浏览文件 @
415b832d
import
{
ApiOptions
,
ApiProtocol
,
ProtocolOptions
}
from
'
../protocols/type
'
type
ApiProtocols
=
ApiProtocol
|
ProtocolOptions
[]
interface
CreateApiOptions
{
type
:
API_TYPES
name
?:
string
options
?:
ApiOptions
}
export
const
API_TYPE_ON
=
0
export
const
API_TYPE_SYNC
=
1
export
const
API_TYPE_ASYNC
=
2
export
const
API_TYPE_RETURN
=
3
type
API_TYPES
=
|
typeof
API_TYPE_ON
|
typeof
API_TYPE_SYNC
|
typeof
API_TYPE_ASYNC
|
typeof
API_TYPE_RETURN
function
validateProtocol
(
name
:
string
,
args
:
any
[],
protocol
:
ApiProtocols
)
{
console
.
log
(
name
,
args
,
protocol
)
return
true
}
function
formatApiArgs
(
args
:
any
[],
options
?:
ApiOptions
)
{
if
(
!
options
)
{
return
args
}
}
export
function
createApi
<
T
extends
Function
>
(
{
type
,
name
,
options
}:
CreateApiOptions
,
fn
:
T
,
protocol
?:
ApiProtocol
|
ProtocolOptions
[],
options
?:
ApiOptions
protocol
?:
ApiProtocols
)
{
if
(
__DEV__
&&
protocol
)
{
}
if
(
options
)
{
console
.
log
(
options
)
return
function
(...
args
:
any
[])
{
if
(
type
===
API_TYPE_SYNC
)
{
if
(
!
(
__DEV__
&&
protocol
&&
!
validateProtocol
(
name
!
,
args
,
protocol
)))
{
return
fn
.
apply
(
null
,
formatApiArgs
(
args
,
options
))
}
}
}
return
fn
}
packages/uni-api/src/index.ts
浏览文件 @
415b832d
...
...
@@ -3,6 +3,7 @@ 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
'
...
...
@@ -21,5 +22,11 @@ export * from './protocols/media/chooseVideo'
export
*
from
'
./protocols/media/getImageInfo
'
// helpers
export
{
createApi
}
from
'
./helpers/api
'
export
{
createApi
,
API_TYPE_ON
,
API_TYPE_SYNC
,
API_TYPE_ASYNC
,
API_TYPE_RETURN
}
from
'
./helpers/api
'
export
{
isSyncApi
,
isContextApi
,
promisify
}
from
'
./helpers/promise
'
packages/uni-api/src/service/base/base64.ts
浏览文件 @
415b832d
// @ts-ignore
import
{
encode
,
decode
}
from
'
../../helpers/base64-arraybuffer
'
import
{
createApi
}
from
'
../../helpers/api
'
import
{
API_TYPE_SYNC
,
createApi
}
from
'
../../helpers/api
'
import
{
Base64ToArrayBufferProtocol
,
...
...
@@ -9,6 +9,7 @@ import {
}
from
'
../../protocols/base/base64
'
export
const
base64ToArrayBuffer
=
createApi
<
typeof
uni
.
base64ToArrayBuffer
>
(
{
type
:
API_TYPE_SYNC
,
name
:
'
base64ToArrayBuffer
'
},
base64
=>
{
return
decode
(
base64
)
as
ArrayBuffer
},
...
...
@@ -16,6 +17,7 @@ export const base64ToArrayBuffer = createApi<typeof uni.base64ToArrayBuffer>(
)
export
const
arrayBufferToBase64
=
createApi
<
typeof
uni
.
arrayBufferToBase64
>
(
{
type
:
API_TYPE_SYNC
,
name
:
'
arrayBufferToBase64
'
},
arrayBuffer
=>
{
return
encode
(
arrayBuffer
)
as
string
},
...
...
packages/uni-api/src/service/base/interceptor.ts
浏览文件 @
415b832d
...
...
@@ -8,7 +8,7 @@ import {
HOOKS
}
from
'
../../helpers/interceptor
'
import
{
createApi
}
from
'
../../helpers/api
'
import
{
API_TYPE_SYNC
,
createApi
}
from
'
../../helpers/api
'
import
{
AddInterceptorProtocol
,
...
...
@@ -80,6 +80,7 @@ function removeHook(hooks: Function[] | undefined, hook: Function) {
}
export
const
addInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
addInterceptor
'
},
(
method
:
string
|
Interceptor
,
interceptor
:
Interceptor
|
undefined
)
=>
{
if
(
typeof
method
===
'
string
'
&&
isPlainObject
(
interceptor
))
{
mergeInterceptorHook
(
...
...
@@ -94,6 +95,7 @@ export const addInterceptor = createApi(
)
export
const
removeInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
removeInterceptor
'
},
(
method
:
string
|
Interceptor
,
interceptor
:
Interceptor
|
undefined
)
=>
{
if
(
typeof
method
===
'
string
'
)
{
if
(
isPlainObject
(
interceptor
))
{
...
...
packages/uni-api/src/service/base/upx2px.ts
浏览文件 @
415b832d
import
{
createApi
}
from
'
../../helpers/api
'
import
{
API_TYPE_SYNC
,
createApi
}
from
'
../../helpers/api
'
import
{
Upx2pxProtocol
}
from
'
../../protocols/base/upx2px
'
const
EPS
=
1
e
-
4
...
...
@@ -15,6 +15,7 @@ function checkDeviceWidth() {
}
export
const
upx2px
=
createApi
<
typeof
uni
.
upx2px
>
(
{
type
:
API_TYPE_SYNC
,
name
:
'
upx2px
'
},
(
number
,
newDeviceWidth
?:
number
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
()
...
...
packages/uni-api/src/service/ui/createIntersectionObserver.ts
浏览文件 @
415b832d
...
...
@@ -2,7 +2,7 @@ import { extend } from '@vue/shared'
import
{
ServiceJSBridge
}
from
'
@dcloudio/uni-core
'
import
{
createApi
}
from
'
../../helpers/api
'
import
{
API_TYPE_RETURN
,
createApi
}
from
'
../../helpers/api
'
import
{
getCurrentPageVm
}
from
'
../utils
'
const
defaultOptions
=
{
...
...
@@ -122,7 +122,7 @@ class ServiceIntersectionObserver {
export
const
createIntersectionObserver
=
createApi
<
typeof
uni
.
createIntersectionObserver
>
((
context
?,
options
?)
=>
{
>
(
{
type
:
API_TYPE_RETURN
},
(
context
?,
options
?)
=>
{
if
(
!
context
)
{
context
=
getCurrentPageVm
()
}
...
...
packages/uni-api/src/service/ui/createSelectorQuery.ts
0 → 100644
浏览文件 @
415b832d
export
const
createSelectorQuery
=
()
=>
{}
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
415b832d
...
...
@@ -1248,12 +1248,26 @@ var decode = function(base64) {
}
return
arraybuffer
;
};
function
createApi
(
fn
,
protocol
,
options
)
{
if
(
process
.
env
.
NODE_ENV
!==
"
production
"
&&
protocol
)
;
if
(
options
)
{
const
API_TYPE_SYNC
=
1
;
const
API_TYPE_ASYNC
=
2
;
const
API_TYPE_RETURN
=
3
;
function
validateProtocol
(
name
,
args
,
protocol
)
{
console
.
log
(
name
,
args
,
protocol
);
return
true
;
}
function
formatApiArgs
(
args
,
options
)
{
if
(
!
options
)
{
return
args
;
}
return
fn
;
}
function
createApi
({
type
:
type2
,
name
,
options
},
fn
,
protocol
)
{
return
function
(...
args
)
{
if
(
type2
===
API_TYPE_SYNC
)
{
if
(
!
(
process
.
env
.
NODE_ENV
!==
"
production
"
&&
protocol
&&
!
validateProtocol
(
name
,
args
,
protocol
)))
{
return
fn
.
apply
(
null
,
formatApiArgs
(
args
,
options
));
}
}
};
}
const
Base64ToArrayBufferProtocol
=
[
{
...
...
@@ -1269,10 +1283,10 @@ const ArrayBufferToBase64Protocol = [
required
:
true
}
];
const
base64ToArrayBuffer
=
/* @__PURE__ */
createApi
((
base642
)
=>
{
const
base64ToArrayBuffer
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
"
base64ToArrayBuffer
"
},
(
base642
)
=>
{
return
decode
(
base642
);
},
Base64ToArrayBufferProtocol
);
const
arrayBufferToBase64
=
/* @__PURE__ */
createApi
((
arrayBuffer
)
=>
{
const
arrayBufferToBase64
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
"
arrayBufferToBase64
"
},
(
arrayBuffer
)
=>
{
return
encode
(
arrayBuffer
);
},
ArrayBufferToBase64Protocol
);
const
Upx2pxProtocol
=
[
...
...
@@ -1293,7 +1307,7 @@ function checkDeviceWidth() {
deviceDPR
=
pixelRatio
;
isIOS
=
platform
===
"
ios
"
;
}
const
upx2px
=
/* @__PURE__ */
createApi
((
number
,
newDeviceWidth
)
=>
{
const
upx2px
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
"
upx2px
"
},
(
number
,
newDeviceWidth
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
();
}
...
...
@@ -1372,14 +1386,14 @@ function removeHook(hooks, hook) {
hooks
.
splice
(
index2
,
1
);
}
}
const
addInterceptor
=
/* @__PURE__ */
createApi
((
method
,
interceptor3
)
=>
{
const
addInterceptor
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
"
addInterceptor
"
},
(
method
,
interceptor3
)
=>
{
if
(
typeof
method
===
"
string
"
&&
isPlainObject
(
interceptor3
))
{
mergeInterceptorHook
(
scopedInterceptors
[
method
]
||
(
scopedInterceptors
[
method
]
=
{}),
interceptor3
);
}
else
if
(
isPlainObject
(
method
))
{
mergeInterceptorHook
(
globalInterceptors
,
method
);
}
},
AddInterceptorProtocol
);
const
removeInterceptor
=
/* @__PURE__ */
createApi
((
method
,
interceptor3
)
=>
{
const
removeInterceptor
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
"
removeInterceptor
"
},
(
method
,
interceptor3
)
=>
{
if
(
typeof
method
===
"
string
"
)
{
if
(
isPlainObject
(
interceptor3
))
{
removeInterceptorHook
(
scopedInterceptors
[
method
],
interceptor3
);
...
...
@@ -1467,12 +1481,14 @@ class ServiceIntersectionObserver {
},
this
.
_pageId
);
}
}
const
createIntersectionObserver$1
=
/* @__PURE__ */
createApi
((
context
,
options
)
=>
{
const
createIntersectionObserver$1
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_RETURN
},
(
context
,
options
)
=>
{
if
(
!
context
)
{
context
=
getCurrentPageVm
();
}
return
new
ServiceIntersectionObserver
(
context
,
options
);
});
const
createSelectorQuery$1
=
()
=>
{
};
const
CanIUseProtocol
=
[
{
name
:
"
schema
"
,
...
...
@@ -1521,19 +1537,19 @@ const SCHEMA_CSS = {
"
css.env
"
:
cssSupports
(
"
top:env(a)
"
),
"
css.constant
"
:
cssSupports
(
"
top:constant(a)
"
)
};
const
canIUse
=
/* @__PURE__ */
createApi
((
schema
)
=>
{
const
canIUse
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
"
canIUse
"
},
(
schema
)
=>
{
if
(
hasOwn
(
SCHEMA_CSS
,
schema
))
{
return
SCHEMA_CSS
[
schema
];
}
return
true
;
},
CanIUseProtocol
);
const
makePhoneCall
=
/* @__PURE__ */
createApi
((
option
)
=>
{
const
makePhoneCall
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_ASYNC
,
name
:
"
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
=
/* @__PURE__ */
createApi
(()
=>
{
const
getSystemInfoSync
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_SYNC
},
()
=>
{
var
screen
=
window
.
screen
;
var
pixelRatio
=
window
.
devicePixelRatio
;
const
screenFix
=
/^Apple/
.
test
(
navigator
.
vendor
)
&&
typeof
window
.
orientation
===
"
number
"
;
...
...
@@ -1634,47 +1650,45 @@ const getSystemInfoSync = /* @__PURE__ */ createApi(() => {
}
};
});
const
getSystemInfo
=
/* @__PURE__ */
createApi
(()
=>
{
const
getSystemInfo
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_ASYNC
,
name
:
"
getSystemInfo
"
},
()
=>
{
return
getSystemInfoSync
();
});
const
openDocument
=
/* @__PURE__ */
createApi
((
option
)
=>
{
const
openDocument
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_ASYNC
,
name
:
"
openDocument
"
},
(
option
)
=>
{
window
.
open
(
option
.
filePath
);
},
OpenDocumentProtocol
);
function
_getServiceAddress
()
{
return
window
.
location
.
protocol
+
"
//
"
+
window
.
location
.
host
;
}
const
getImageInfo
=
/* @__PURE__ */
createApi
(({
src
},
callbackId
)
=>
{
const
{
invokeCallbackHandler
:
invoke
}
=
UniServiceJSBridge
;
const
getImageInfo
=
/* @__PURE__ */
createApi
({
type
:
API_TYPE_ASYNC
,
name
:
"
getImageInfo
"
,
options
:
GetImageInfoOptions
},
({
src
},
callback
)
=>
{
const
img
=
new
Image
();
const
realPath
=
src
;
img
.
onload
=
function
()
{
invoke
(
callbackId
,
{
callback
(
{
errMsg
:
"
getImageInfo:ok
"
,
width
:
img
.
naturalWidth
,
height
:
img
.
naturalHeight
,
path
:
realPath
.
indexOf
(
"
/
"
)
===
0
?
_getServiceAddress
()
+
realPath
:
realPath
path
:
src
.
indexOf
(
"
/
"
)
===
0
?
_getServiceAddress
()
+
src
:
src
});
};
img
.
onerror
=
function
()
{
invoke
(
callbackId
,
{
callback
(
{
errMsg
:
"
getImageInfo:fail
"
});
};
img
.
src
=
src
;
},
GetImageInfoProtocol
,
GetImageInfoOptions
);
const
navigateBack
=
/* @__PURE__ */
createApi
(()
=>
{
},
GetImageInfoProtocol
);
const
navigateBack
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_ASYNC
},
()
=>
{
});
const
navigateTo
=
/* @__PURE__ */
createApi
((
options
)
=>
{
const
navigateTo
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_ASYNC
},
(
options
)
=>
{
const
router
=
getApp
().
$router
;
router
.
push
(
options
.
url
);
});
const
redirectTo
=
/* @__PURE__ */
createApi
(()
=>
{
const
redirectTo
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_ASYNC
},
()
=>
{
});
const
reLaunch
=
/* @__PURE__ */
createApi
(()
=>
{
const
reLaunch
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_ASYNC
},
()
=>
{
});
const
switchTab
=
/* @__PURE__ */
createApi
(()
=>
{
const
switchTab
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_ASYNC
},
()
=>
{
});
const
getRealPath
=
/* @__PURE__ */
createApi
((
path
)
=>
{
const
getRealPath
=
/* @__PURE__ */
createApi
(
{
type
:
API_TYPE_SYNC
},
(
path
)
=>
{
return
path
;
});
var
api
=
/* @__PURE__ */
Object
.
freeze
({
...
...
@@ -1686,6 +1700,7 @@ var api = /* @__PURE__ */ Object.freeze({
arrayBufferToBase64
,
base64ToArrayBuffer
,
createIntersectionObserver
:
createIntersectionObserver$1
,
createSelectorQuery
:
createSelectorQuery$1
,
canIUse
,
makePhoneCall
,
getSystemInfo
,
...
...
@@ -2831,4 +2846,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
,
UniServiceJSBridge$1
as
UniServiceJSBridge
,
UniViewJSBridge$1
as
UniViewJSBridge
,
addInterceptor
,
arrayBufferToBase64
,
base64ToArrayBuffer
,
canIUse
,
createIntersectionObserver$1
as
createIntersectionObserver
,
getApp$1
as
getApp
,
getCurrentPages$1
as
getCurrentPages
,
getImageInfo
,
getRealPath
,
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
,
UniServiceJSBridge$1
as
UniServiceJSBridge
,
UniViewJSBridge$1
as
UniViewJSBridge
,
addInterceptor
,
arrayBufferToBase64
,
base64ToArrayBuffer
,
canIUse
,
createIntersectionObserver$1
as
createIntersectionObserver
,
createSelectorQuery$1
as
createSelectorQuery
,
getApp$1
as
getApp
,
getCurrentPages$1
as
getCurrentPages
,
getImageInfo
,
getRealPath
,
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
浏览文件 @
415b832d
import
{
hasOwn
}
from
'
@vue/shared
'
import
{
createApi
,
CanIUseProtocol
}
from
'
@dcloudio/uni-api
'
import
{
createApi
,
CanIUseProtocol
,
API_TYPE_SYNC
}
from
'
@dcloudio/uni-api
'
function
cssSupports
(
css
:
string
)
{
return
window
.
CSS
&&
window
.
CSS
.
supports
&&
window
.
CSS
.
supports
(
css
)
...
...
@@ -12,9 +12,13 @@ const SCHEMA_CSS = {
'
css.constant
'
:
cssSupports
(
'
top:constant(a)
'
)
}
export
const
canIUse
=
createApi
<
typeof
uni
.
canIUse
>
((
schema
:
string
)
=>
{
if
(
hasOwn
(
SCHEMA_CSS
,
schema
))
{
return
SCHEMA_CSS
[
schema
]
}
return
true
},
CanIUseProtocol
)
export
const
canIUse
=
createApi
<
typeof
uni
.
canIUse
>
(
{
type
:
API_TYPE_SYNC
,
name
:
'
canIUse
'
},
(
schema
:
string
)
=>
{
if
(
hasOwn
(
SCHEMA_CSS
,
schema
))
{
return
SCHEMA_CSS
[
schema
]
}
return
true
},
CanIUseProtocol
)
packages/uni-h5/src/service/api/device/getSystemInfo.ts
浏览文件 @
415b832d
import
{
createApi
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_ASYNC
,
createApi
}
from
'
@dcloudio/uni-api
'
import
{
getSystemInfoSync
}
from
'
./getSystemInfoSync
'
export
const
getSystemInfo
=
createApi
<
typeof
uni
.
getSystemInfo
>
(()
=>
{
return
getSystemInfoSync
()
})
export
const
getSystemInfo
=
createApi
<
typeof
uni
.
getSystemInfo
>
(
{
type
:
API_TYPE_ASYNC
,
name
:
'
getSystemInfo
'
},
()
=>
{
return
getSystemInfoSync
()
}
)
packages/uni-h5/src/service/api/device/getSystemInfoSync.ts
浏览文件 @
415b832d
import
safeAreaInsets
from
'
safe-area-insets
'
import
{
createApi
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_SYNC
,
createApi
}
from
'
@dcloudio/uni-api
'
import
{
getWindowOffset
}
from
'
@dcloudio/uni-core
'
...
...
@@ -16,122 +16,125 @@ const isIOS = /iphone|ipad|ipod/i.test(ua)
/**
* 获取系统信息-同步
*/
export
const
getSystemInfoSync
=
createApi
<
typeof
uni
.
getSystemInfoSync
>
(()
=>
{
var
screen
=
window
.
screen
var
pixelRatio
=
window
.
devicePixelRatio
// 横屏时 iOS 获取的屏幕宽高颠倒,进行纠正
const
screenFix
=
/^Apple/
.
test
(
navigator
.
vendor
)
&&
typeof
window
.
orientation
===
'
number
'
const
landscape
=
screenFix
&&
Math
.
abs
(
window
.
orientation
as
number
)
===
90
var
screenWidth
=
screenFix
?
Math
[
landscape
?
'
max
'
:
'
min
'
](
screen
.
width
,
screen
.
height
)
:
screen
.
width
var
screenHeight
=
screenFix
?
Math
[
landscape
?
'
min
'
:
'
max
'
](
screen
.
height
,
screen
.
width
)
:
screen
.
height
var
windowWidth
=
Math
.
min
(
window
.
innerWidth
,
document
.
documentElement
.
clientWidth
,
screenWidth
)
||
screenWidth
var
windowHeight
=
window
.
innerHeight
var
language
=
navigator
.
language
var
statusBarHeight
=
safeAreaInsets
.
top
var
osname
var
osversion
var
model
export
const
getSystemInfoSync
=
createApi
<
typeof
uni
.
getSystemInfoSync
>
(
{
type
:
API_TYPE_SYNC
},
()
=>
{
var
screen
=
window
.
screen
var
pixelRatio
=
window
.
devicePixelRatio
// 横屏时 iOS 获取的屏幕宽高颠倒,进行纠正
const
screenFix
=
/^Apple/
.
test
(
navigator
.
vendor
)
&&
typeof
window
.
orientation
===
'
number
'
const
landscape
=
screenFix
&&
Math
.
abs
(
window
.
orientation
as
number
)
===
90
var
screenWidth
=
screenFix
?
Math
[
landscape
?
'
max
'
:
'
min
'
](
screen
.
width
,
screen
.
height
)
:
screen
.
width
var
screenHeight
=
screenFix
?
Math
[
landscape
?
'
min
'
:
'
max
'
](
screen
.
height
,
screen
.
width
)
:
screen
.
height
var
windowWidth
=
Math
.
min
(
window
.
innerWidth
,
document
.
documentElement
.
clientWidth
,
screenWidth
)
||
screenWidth
var
windowHeight
=
window
.
innerHeight
var
language
=
navigator
.
language
var
statusBarHeight
=
safeAreaInsets
.
top
var
osname
var
osversion
var
model
if
(
isIOS
)
{
osname
=
'
iOS
'
const
osversionFind
=
ua
.
match
(
/OS
\s([\w
_
]
+
)\s
like/
)
if
(
osversionFind
)
{
osversion
=
osversionFind
[
1
].
replace
(
/_/g
,
'
.
'
)
}
const
modelFind
=
ua
.
match
(
/
\(([
a-zA-Z
]
+
)
;/
)
if
(
modelFind
)
{
model
=
modelFind
[
1
]
}
}
else
if
(
isAndroid
)
{
osname
=
'
Android
'
// eslint-disable-next-line no-useless-escape
const
osversionFind
=
ua
.
match
(
/Android
[\s/]([\w\.]
+
)[
;
\s]
/
)
if
(
osversionFind
)
{
osversion
=
osversionFind
[
1
]
}
const
infoFind
=
ua
.
match
(
/
\((
.+
?)\)
/
)
const
infos
=
infoFind
?
infoFind
[
1
].
split
(
'
;
'
)
:
ua
.
split
(
'
'
)
// eslint-disable-next-line no-useless-escape
const
otherInfo
=
[
/
\b
Android
\b
/i
,
/
\b
Linux
\b
/i
,
/
\b
U
\b
/i
,
/^
\s?[
a-z
][
a-z
]
$/i
,
/^
\s?[
a-z
][
a-z
]
-
[
a-z
][
a-z
]
$/i
,
/
\b
wv
\b
/i
,
/
\/[\d\.
,
]
+$/
,
/^
\s?[\d\.
,
]
+$/
,
/
\b
Browser
\b
/i
,
/
\b
Mobile
\b
/i
]
for
(
let
i
=
0
;
i
<
infos
.
length
;
i
++
)
{
const
info
=
infos
[
i
]
if
(
info
.
indexOf
(
'
Build
'
)
>
0
)
{
model
=
info
.
split
(
'
Build
'
)[
0
].
trim
()
break
if
(
isIOS
)
{
osname
=
'
iOS
'
const
osversionFind
=
ua
.
match
(
/OS
\s([\w
_
]
+
)\s
like/
)
if
(
osversionFind
)
{
osversion
=
osversionFind
[
1
].
replace
(
/_/g
,
'
.
'
)
}
const
modelFind
=
ua
.
match
(
/
\(([
a-zA-Z
]
+
)
;/
)
if
(
modelFind
)
{
model
=
modelFind
[
1
]
}
}
else
if
(
isAndroid
)
{
osname
=
'
Android
'
// eslint-disable-next-line no-useless-escape
const
osversionFind
=
ua
.
match
(
/Android
[\s/]([\w\.]
+
)[
;
\s]
/
)
if
(
osversionFind
)
{
osversion
=
osversionFind
[
1
]
}
let
other
for
(
let
o
=
0
;
o
<
otherInfo
.
length
;
o
++
)
{
if
(
otherInfo
[
o
].
test
(
info
))
{
other
=
true
const
infoFind
=
ua
.
match
(
/
\((
.+
?)\)
/
)
const
infos
=
infoFind
?
infoFind
[
1
].
split
(
'
;
'
)
:
ua
.
split
(
'
'
)
// eslint-disable-next-line no-useless-escape
const
otherInfo
=
[
/
\b
Android
\b
/i
,
/
\b
Linux
\b
/i
,
/
\b
U
\b
/i
,
/^
\s?[
a-z
][
a-z
]
$/i
,
/^
\s?[
a-z
][
a-z
]
-
[
a-z
][
a-z
]
$/i
,
/
\b
wv
\b
/i
,
/
\/[\d\.
,
]
+$/
,
/^
\s?[\d\.
,
]
+$/
,
/
\b
Browser
\b
/i
,
/
\b
Mobile
\b
/i
]
for
(
let
i
=
0
;
i
<
infos
.
length
;
i
++
)
{
const
info
=
infos
[
i
]
if
(
info
.
indexOf
(
'
Build
'
)
>
0
)
{
model
=
info
.
split
(
'
Build
'
)[
0
].
trim
()
break
}
let
other
for
(
let
o
=
0
;
o
<
otherInfo
.
length
;
o
++
)
{
if
(
otherInfo
[
o
].
test
(
info
))
{
other
=
true
break
}
}
if
(
!
other
)
{
model
=
info
.
trim
()
break
}
}
if
(
!
other
)
{
model
=
info
.
trim
()
break
}
}
else
{
osname
=
'
Other
'
osversion
=
'
0
'
}
}
else
{
osname
=
'
Other
'
osversion
=
'
0
'
}
var
system
=
`
${
osname
}
${
osversion
}
`
var
platform
=
osname
.
toLocaleLowerCase
()
var
safeArea
=
{
left
:
safeAreaInsets
.
left
,
right
:
windowWidth
-
safeAreaInsets
.
right
,
top
:
safeAreaInsets
.
top
,
bottom
:
windowHeight
-
safeAreaInsets
.
bottom
,
width
:
windowWidth
-
safeAreaInsets
.
left
-
safeAreaInsets
.
right
,
height
:
windowHeight
-
safeAreaInsets
.
top
-
safeAreaInsets
.
bottom
}
var
system
=
`
${
osname
}
${
osversion
}
`
var
platform
=
osname
.
toLocaleLowerCase
()
var
safeArea
=
{
left
:
safeAreaInsets
.
left
,
right
:
windowWidth
-
safeAreaInsets
.
right
,
top
:
safeAreaInsets
.
top
,
bottom
:
windowHeight
-
safeAreaInsets
.
bottom
,
width
:
windowWidth
-
safeAreaInsets
.
left
-
safeAreaInsets
.
right
,
height
:
windowHeight
-
safeAreaInsets
.
top
-
safeAreaInsets
.
bottom
}
const
{
top
:
windowTop
,
bottom
:
windowBottom
}
=
getWindowOffset
()
const
{
top
:
windowTop
,
bottom
:
windowBottom
}
=
getWindowOffset
()
windowHeight
-=
windowTop
windowHeight
-=
windowBottom
windowHeight
-=
windowTop
windowHeight
-=
windowBottom
return
{
windowTop
,
windowBottom
,
windowWidth
,
windowHeight
,
pixelRatio
,
screenWidth
,
screenHeight
,
language
,
statusBarHeight
,
system
,
platform
,
model
,
safeArea
,
safeAreaInsets
:
{
top
:
safeAreaInsets
.
top
,
right
:
safeAreaInsets
.
right
,
bottom
:
safeAreaInsets
.
bottom
,
left
:
safeAreaInsets
.
left
}
}
as
UniApp
.
GetSystemInfoResult
})
return
{
windowTop
,
windowBottom
,
windowWidth
,
windowHeight
,
pixelRatio
,
screenWidth
,
screenHeight
,
language
,
statusBarHeight
,
system
,
platform
,
model
,
safeArea
,
safeAreaInsets
:
{
top
:
safeAreaInsets
.
top
,
right
:
safeAreaInsets
.
right
,
bottom
:
safeAreaInsets
.
bottom
,
left
:
safeAreaInsets
.
left
}
}
as
UniApp
.
GetSystemInfoResult
}
)
packages/uni-h5/src/service/api/device/makePhoneCall.ts
浏览文件 @
415b832d
import
{
createApi
,
MakePhoneCallProtocol
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_ASYNC
,
createApi
,
MakePhoneCallProtocol
}
from
'
@dcloudio/uni-api
'
export
const
makePhoneCall
=
createApi
<
typeof
uni
.
makePhoneCall
>
(
option
=>
{
window
.
location
.
href
=
`tel:
${
option
.
phoneNumber
}
`
},
MakePhoneCallProtocol
)
export
const
makePhoneCall
=
createApi
<
typeof
uni
.
makePhoneCall
>
(
{
type
:
API_TYPE_ASYNC
,
name
:
'
makePhoneCall
'
},
option
=>
{
window
.
location
.
href
=
`tel:
${
option
.
phoneNumber
}
`
},
MakePhoneCallProtocol
)
packages/uni-h5/src/service/api/file/openDocument.ts
浏览文件 @
415b832d
import
{
createApi
,
OpenDocumentProtocol
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_ASYNC
,
createApi
,
OpenDocumentProtocol
}
from
'
@dcloudio/uni-api
'
export
const
openDocument
=
createApi
<
typeof
uni
.
openDocument
>
(
option
=>
{
window
.
open
(
option
.
filePath
)
},
OpenDocumentProtocol
)
export
const
openDocument
=
createApi
<
typeof
uni
.
openDocument
>
(
{
type
:
API_TYPE_ASYNC
,
name
:
'
openDocument
'
},
option
=>
{
window
.
open
(
option
.
filePath
)
},
OpenDocumentProtocol
)
packages/uni-h5/src/service/api/index.ts
浏览文件 @
415b832d
...
...
@@ -23,5 +23,6 @@ export {
promiseInterceptor
,
arrayBufferToBase64
,
base64ToArrayBuffer
,
createIntersectionObserver
createIntersectionObserver
,
createSelectorQuery
}
from
'
@dcloudio/uni-api
'
packages/uni-h5/src/service/api/media/getImageInfo.ts
浏览文件 @
415b832d
import
{
API_TYPE_ASYNC
,
createApi
,
GetImageInfoOptions
,
GetImageInfoProtocol
...
...
@@ -9,28 +10,23 @@ function _getServiceAddress() {
}
export
const
getImageInfo
=
createApi
<
typeof
uni
.
getImageInfo
>
(
({
src
},
callbackId
?:
number
)
=>
{
const
{
invokeCallbackHandler
:
invoke
}
=
UniServiceJSBridge
{
type
:
API_TYPE_ASYNC
,
name
:
'
getImageInfo
'
,
options
:
GetImageInfoOptions
},
({
src
},
callback
?:
Function
)
=>
{
const
img
=
new
Image
()
const
realPath
=
src
img
.
onload
=
function
()
{
invoke
(
callbackId
,
{
callback
!
(
{
errMsg
:
'
getImageInfo:ok
'
,
width
:
img
.
naturalWidth
,
height
:
img
.
naturalHeight
,
path
:
realPath
.
indexOf
(
'
/
'
)
===
0
?
_getServiceAddress
()
+
realPath
:
realPath
path
:
src
.
indexOf
(
'
/
'
)
===
0
?
_getServiceAddress
()
+
src
:
src
})
}
img
.
onerror
=
function
()
{
invoke
(
callbackId
,
{
callback
!
(
{
errMsg
:
'
getImageInfo:fail
'
})
}
img
.
src
=
src
},
GetImageInfoProtocol
,
GetImageInfoOptions
GetImageInfoProtocol
)
packages/uni-h5/src/service/api/route/navigateBack.ts
浏览文件 @
415b832d
import
{
createApi
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_ASYNC
,
createApi
}
from
'
@dcloudio/uni-api
'
export
const
navigateBack
=
createApi
<
typeof
uni
.
navigateBack
>
(()
=>
{})
export
const
navigateBack
=
createApi
<
typeof
uni
.
navigateBack
>
(
{
type
:
API_TYPE_ASYNC
},
()
=>
{}
)
packages/uni-h5/src/service/api/route/navigateTo.ts
浏览文件 @
415b832d
import
{
createApi
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_ASYNC
,
createApi
}
from
'
@dcloudio/uni-api
'
export
const
navigateTo
=
createApi
<
typeof
uni
.
navigateTo
>
(
options
=>
{
const
router
=
getApp
().
$router
router
.
push
(
options
.
url
)
})
export
const
navigateTo
=
createApi
<
typeof
uni
.
navigateTo
>
(
{
type
:
API_TYPE_ASYNC
},
options
=>
{
const
router
=
getApp
().
$router
router
.
push
(
options
.
url
)
}
)
packages/uni-h5/src/service/api/route/reLaunch.ts
浏览文件 @
415b832d
import
{
createApi
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_ASYNC
,
createApi
}
from
'
@dcloudio/uni-api
'
export
const
reLaunch
=
createApi
(()
=>
{})
export
const
reLaunch
=
createApi
(
{
type
:
API_TYPE_ASYNC
},
()
=>
{})
packages/uni-h5/src/service/api/route/redirectTo.ts
浏览文件 @
415b832d
import
{
createApi
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_ASYNC
,
createApi
}
from
'
@dcloudio/uni-api
'
export
const
redirectTo
=
createApi
(()
=>
{})
export
const
redirectTo
=
createApi
(
{
type
:
API_TYPE_ASYNC
},
()
=>
{})
packages/uni-h5/src/service/api/route/switchTab.ts
浏览文件 @
415b832d
import
{
createApi
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_ASYNC
,
createApi
}
from
'
@dcloudio/uni-api
'
export
const
switchTab
=
createApi
(()
=>
{})
export
const
switchTab
=
createApi
(
{
type
:
API_TYPE_ASYNC
},
()
=>
{})
packages/uni-h5/src/service/api/util/getRealPath.ts
浏览文件 @
415b832d
import
{
createApi
}
from
'
@dcloudio/uni-api
'
import
{
API_TYPE_SYNC
,
createApi
}
from
'
@dcloudio/uni-api
'
export
const
getRealPath
=
createApi
((
path
:
string
)
=>
{
return
path
})
export
const
getRealPath
=
createApi
(
{
type
:
API_TYPE_SYNC
},
(
path
:
string
)
=>
{
return
path
}
)
packages/uni-mp-alipay/dist/uni.api.esm.js
浏览文件 @
415b832d
import
{
isArray
,
isPromise
,
isFunction
,
isPlainObject
,
hasOwn
,
isString
}
from
'
@vue/shared
'
;
function
createApi
(
fn
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
)
;
return
fn
;
const
API_TYPE_SYNC
=
1
;
function
validateProtocol
(
name
,
args
,
protocol
)
{
console
.
log
(
name
,
args
,
protocol
);
return
true
;
}
function
formatApiArgs
(
args
,
options
)
{
if
(
!
options
)
{
return
args
;
}
}
function
createApi
({
type
,
name
,
options
},
fn
,
protocol
)
{
return
function
(...
args
)
{
if
(
type
===
API_TYPE_SYNC
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
(
name
,
args
,
protocol
)))
{
return
fn
.
apply
(
null
,
formatApiArgs
(
args
,
options
));
}
}
};
}
const
Upx2pxProtocol
=
[
...
...
@@ -24,7 +39,7 @@ function checkDeviceWidth() {
deviceDPR
=
pixelRatio
;
isIOS
=
platform
===
'
ios
'
;
}
const
upx2px
=
createApi
((
number
,
newDeviceWidth
)
=>
{
const
upx2px
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
upx2px
'
},
(
number
,
newDeviceWidth
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
();
}
...
...
@@ -206,7 +221,7 @@ function removeHook(hooks, hook) {
hooks
.
splice
(
index
,
1
);
}
}
const
addInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
addInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
addInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
&&
isPlainObject
(
interceptor
))
{
mergeInterceptorHook
(
scopedInterceptors
[
method
]
||
(
scopedInterceptors
[
method
]
=
{}),
interceptor
);
}
...
...
@@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => {
mergeInterceptorHook
(
globalInterceptors
,
method
);
}
},
AddInterceptorProtocol
);
const
removeInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
removeInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
removeInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
)
{
if
(
isPlainObject
(
interceptor
))
{
removeInterceptorHook
(
scopedInterceptors
[
method
],
interceptor
);
...
...
packages/uni-mp-baidu/dist/uni.api.esm.js
浏览文件 @
415b832d
import
{
isArray
,
isPromise
,
isFunction
,
isPlainObject
,
hasOwn
,
isString
}
from
'
@vue/shared
'
;
function
createApi
(
fn
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
)
;
return
fn
;
const
API_TYPE_SYNC
=
1
;
function
validateProtocol
(
name
,
args
,
protocol
)
{
console
.
log
(
name
,
args
,
protocol
);
return
true
;
}
function
formatApiArgs
(
args
,
options
)
{
if
(
!
options
)
{
return
args
;
}
}
function
createApi
({
type
,
name
,
options
},
fn
,
protocol
)
{
return
function
(...
args
)
{
if
(
type
===
API_TYPE_SYNC
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
(
name
,
args
,
protocol
)))
{
return
fn
.
apply
(
null
,
formatApiArgs
(
args
,
options
));
}
}
};
}
const
Upx2pxProtocol
=
[
...
...
@@ -24,7 +39,7 @@ function checkDeviceWidth() {
deviceDPR
=
pixelRatio
;
isIOS
=
platform
===
'
ios
'
;
}
const
upx2px
=
createApi
((
number
,
newDeviceWidth
)
=>
{
const
upx2px
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
upx2px
'
},
(
number
,
newDeviceWidth
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
();
}
...
...
@@ -206,7 +221,7 @@ function removeHook(hooks, hook) {
hooks
.
splice
(
index
,
1
);
}
}
const
addInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
addInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
addInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
&&
isPlainObject
(
interceptor
))
{
mergeInterceptorHook
(
scopedInterceptors
[
method
]
||
(
scopedInterceptors
[
method
]
=
{}),
interceptor
);
}
...
...
@@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => {
mergeInterceptorHook
(
globalInterceptors
,
method
);
}
},
AddInterceptorProtocol
);
const
removeInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
removeInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
removeInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
)
{
if
(
isPlainObject
(
interceptor
))
{
removeInterceptorHook
(
scopedInterceptors
[
method
],
interceptor
);
...
...
packages/uni-mp-qq/dist/uni.api.esm.js
浏览文件 @
415b832d
import
{
isArray
,
isPromise
,
isFunction
,
isPlainObject
,
hasOwn
,
isString
}
from
'
@vue/shared
'
;
function
createApi
(
fn
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
)
;
return
fn
;
const
API_TYPE_SYNC
=
1
;
function
validateProtocol
(
name
,
args
,
protocol
)
{
console
.
log
(
name
,
args
,
protocol
);
return
true
;
}
function
formatApiArgs
(
args
,
options
)
{
if
(
!
options
)
{
return
args
;
}
}
function
createApi
({
type
,
name
,
options
},
fn
,
protocol
)
{
return
function
(...
args
)
{
if
(
type
===
API_TYPE_SYNC
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
(
name
,
args
,
protocol
)))
{
return
fn
.
apply
(
null
,
formatApiArgs
(
args
,
options
));
}
}
};
}
const
Upx2pxProtocol
=
[
...
...
@@ -24,7 +39,7 @@ function checkDeviceWidth() {
deviceDPR
=
pixelRatio
;
isIOS
=
platform
===
'
ios
'
;
}
const
upx2px
=
createApi
((
number
,
newDeviceWidth
)
=>
{
const
upx2px
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
upx2px
'
},
(
number
,
newDeviceWidth
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
();
}
...
...
@@ -206,7 +221,7 @@ function removeHook(hooks, hook) {
hooks
.
splice
(
index
,
1
);
}
}
const
addInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
addInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
addInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
&&
isPlainObject
(
interceptor
))
{
mergeInterceptorHook
(
scopedInterceptors
[
method
]
||
(
scopedInterceptors
[
method
]
=
{}),
interceptor
);
}
...
...
@@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => {
mergeInterceptorHook
(
globalInterceptors
,
method
);
}
},
AddInterceptorProtocol
);
const
removeInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
removeInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
removeInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
)
{
if
(
isPlainObject
(
interceptor
))
{
removeInterceptorHook
(
scopedInterceptors
[
method
],
interceptor
);
...
...
packages/uni-mp-toutiao/dist/uni.api.esm.js
浏览文件 @
415b832d
import
{
isArray
,
isPromise
,
isFunction
,
isPlainObject
,
hasOwn
,
isString
}
from
'
@vue/shared
'
;
function
createApi
(
fn
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
)
;
return
fn
;
const
API_TYPE_SYNC
=
1
;
function
validateProtocol
(
name
,
args
,
protocol
)
{
console
.
log
(
name
,
args
,
protocol
);
return
true
;
}
function
formatApiArgs
(
args
,
options
)
{
if
(
!
options
)
{
return
args
;
}
}
function
createApi
({
type
,
name
,
options
},
fn
,
protocol
)
{
return
function
(...
args
)
{
if
(
type
===
API_TYPE_SYNC
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
(
name
,
args
,
protocol
)))
{
return
fn
.
apply
(
null
,
formatApiArgs
(
args
,
options
));
}
}
};
}
const
Upx2pxProtocol
=
[
...
...
@@ -24,7 +39,7 @@ function checkDeviceWidth() {
deviceDPR
=
pixelRatio
;
isIOS
=
platform
===
'
ios
'
;
}
const
upx2px
=
createApi
((
number
,
newDeviceWidth
)
=>
{
const
upx2px
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
upx2px
'
},
(
number
,
newDeviceWidth
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
();
}
...
...
@@ -206,7 +221,7 @@ function removeHook(hooks, hook) {
hooks
.
splice
(
index
,
1
);
}
}
const
addInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
addInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
addInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
&&
isPlainObject
(
interceptor
))
{
mergeInterceptorHook
(
scopedInterceptors
[
method
]
||
(
scopedInterceptors
[
method
]
=
{}),
interceptor
);
}
...
...
@@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => {
mergeInterceptorHook
(
globalInterceptors
,
method
);
}
},
AddInterceptorProtocol
);
const
removeInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
removeInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
removeInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
)
{
if
(
isPlainObject
(
interceptor
))
{
removeInterceptorHook
(
scopedInterceptors
[
method
],
interceptor
);
...
...
packages/uni-mp-weixin/dist/uni.api.esm.js
浏览文件 @
415b832d
import
{
isArray
,
isPromise
,
isFunction
,
isPlainObject
,
hasOwn
,
isString
}
from
'
@vue/shared
'
;
function
createApi
(
fn
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
)
;
return
fn
;
const
API_TYPE_SYNC
=
1
;
function
validateProtocol
(
name
,
args
,
protocol
)
{
console
.
log
(
name
,
args
,
protocol
);
return
true
;
}
function
formatApiArgs
(
args
,
options
)
{
if
(
!
options
)
{
return
args
;
}
}
function
createApi
({
type
,
name
,
options
},
fn
,
protocol
)
{
return
function
(...
args
)
{
if
(
type
===
API_TYPE_SYNC
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
(
name
,
args
,
protocol
)))
{
return
fn
.
apply
(
null
,
formatApiArgs
(
args
,
options
));
}
}
};
}
const
Upx2pxProtocol
=
[
...
...
@@ -24,7 +39,7 @@ function checkDeviceWidth() {
deviceDPR
=
pixelRatio
;
isIOS
=
platform
===
'
ios
'
;
}
const
upx2px
=
createApi
((
number
,
newDeviceWidth
)
=>
{
const
upx2px
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
upx2px
'
},
(
number
,
newDeviceWidth
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
();
}
...
...
@@ -206,7 +221,7 @@ function removeHook(hooks, hook) {
hooks
.
splice
(
index
,
1
);
}
}
const
addInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
addInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
addInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
&&
isPlainObject
(
interceptor
))
{
mergeInterceptorHook
(
scopedInterceptors
[
method
]
||
(
scopedInterceptors
[
method
]
=
{}),
interceptor
);
}
...
...
@@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => {
mergeInterceptorHook
(
globalInterceptors
,
method
);
}
},
AddInterceptorProtocol
);
const
removeInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
removeInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
removeInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
)
{
if
(
isPlainObject
(
interceptor
))
{
removeInterceptorHook
(
scopedInterceptors
[
method
],
interceptor
);
...
...
packages/uni-quickapp-webview/dist/uni.api.esm.js
浏览文件 @
415b832d
import
{
isArray
,
isPromise
,
isFunction
,
isPlainObject
,
hasOwn
,
isString
}
from
'
@vue/shared
'
;
function
createApi
(
fn
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
)
;
return
fn
;
const
API_TYPE_SYNC
=
1
;
function
validateProtocol
(
name
,
args
,
protocol
)
{
console
.
log
(
name
,
args
,
protocol
);
return
true
;
}
function
formatApiArgs
(
args
,
options
)
{
if
(
!
options
)
{
return
args
;
}
}
function
createApi
({
type
,
name
,
options
},
fn
,
protocol
)
{
return
function
(...
args
)
{
if
(
type
===
API_TYPE_SYNC
)
{
if
(
!
((
process
.
env
.
NODE_ENV
!==
'
production
'
)
&&
protocol
&&
!
validateProtocol
(
name
,
args
,
protocol
)))
{
return
fn
.
apply
(
null
,
formatApiArgs
(
args
,
options
));
}
}
};
}
const
Upx2pxProtocol
=
[
...
...
@@ -24,7 +39,7 @@ function checkDeviceWidth() {
deviceDPR
=
pixelRatio
;
isIOS
=
platform
===
'
ios
'
;
}
const
upx2px
=
createApi
((
number
,
newDeviceWidth
)
=>
{
const
upx2px
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
upx2px
'
},
(
number
,
newDeviceWidth
)
=>
{
if
(
deviceWidth
===
0
)
{
checkDeviceWidth
();
}
...
...
@@ -206,7 +221,7 @@ function removeHook(hooks, hook) {
hooks
.
splice
(
index
,
1
);
}
}
const
addInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
addInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
addInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
&&
isPlainObject
(
interceptor
))
{
mergeInterceptorHook
(
scopedInterceptors
[
method
]
||
(
scopedInterceptors
[
method
]
=
{}),
interceptor
);
}
...
...
@@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => {
mergeInterceptorHook
(
globalInterceptors
,
method
);
}
},
AddInterceptorProtocol
);
const
removeInterceptor
=
createApi
((
method
,
interceptor
)
=>
{
const
removeInterceptor
=
createApi
(
{
type
:
API_TYPE_SYNC
,
name
:
'
removeInterceptor
'
},
(
method
,
interceptor
)
=>
{
if
(
typeof
method
===
'
string
'
)
{
if
(
isPlainObject
(
interceptor
))
{
removeInterceptorHook
(
scopedInterceptors
[
method
],
interceptor
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录