Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
touchx
uni-app
提交
90e93c2c
U
uni-app
项目概览
touchx
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
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,发现更多精彩内容 >>
提交
90e93c2c
编写于
4月 20, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(push): v2
上级
1b5464da
变更
44
展开全部
隐藏空白更改
内联
并排
Showing
44 changed file
with
2826 addition
and
893 deletion
+2826
-893
.eslintignore
.eslintignore
+1
-0
build/rollup.config.mp.js
build/rollup.config.mp.js
+6
-0
lib/apis.js
lib/apis.js
+10
-2
packages/uni-app-plus/dist/index.js
packages/uni-app-plus/dist/index.js
+1
-1
packages/uni-app-plus/dist/index.v3.js
packages/uni-app-plus/dist/index.v3.js
+617
-436
packages/uni-cli-shared/lib/index.js
packages/uni-cli-shared/lib/index.js
+4
-2
packages/uni-cli-shared/lib/manifest.js
packages/uni-cli-shared/lib/manifest.js
+32
-3
packages/uni-cli-shared/lib/platform.js
packages/uni-cli-shared/lib/platform.js
+194
-185
packages/uni-h5/dist/index.umd.min.js
packages/uni-h5/dist/index.umd.min.js
+1
-1
packages/uni-h5/manifest.json
packages/uni-h5/manifest.json
+16
-0
packages/uni-mp-alipay/dist/index.js
packages/uni-mp-alipay/dist/index.js
+210
-78
packages/uni-mp-baidu/dist/index.js
packages/uni-mp-baidu/dist/index.js
+146
-18
packages/uni-mp-jd/dist/index.js
packages/uni-mp-jd/dist/index.js
+130
-2
packages/uni-mp-kuaishou/dist/index.js
packages/uni-mp-kuaishou/dist/index.js
+130
-2
packages/uni-mp-lark/dist/index.js
packages/uni-mp-lark/dist/index.js
+130
-2
packages/uni-mp-qq/dist/index.js
packages/uni-mp-qq/dist/index.js
+130
-2
packages/uni-mp-toutiao/dist/index.js
packages/uni-mp-toutiao/dist/index.js
+130
-2
packages/uni-mp-weixin/dist/index.js
packages/uni-mp-weixin/dist/index.js
+130
-2
packages/uni-mp-xhs/dist/index.js
packages/uni-mp-xhs/dist/index.js
+130
-2
packages/uni-quickapp-native/dist/vue.dev.js
packages/uni-quickapp-native/dist/vue.dev.js
+1
-1
packages/uni-quickapp-native/dist/vue.prod.js
packages/uni-quickapp-native/dist/vue.prod.js
+1
-1
packages/uni-quickapp-webview/dist/index.js
packages/uni-quickapp-webview/dist/index.js
+130
-2
packages/vue-cli-plugin-uni/lib/app-plus/index.js
packages/vue-cli-plugin-uni/lib/app-plus/index.js
+5
-3
packages/vue-cli-plugin-uni/lib/env.js
packages/vue-cli-plugin-uni/lib/env.js
+14
-1
packages/vue-cli-plugin-uni/lib/h5/index.js
packages/vue-cli-plugin-uni/lib/h5/index.js
+5
-4
packages/vue-cli-plugin-uni/lib/mp/index.js
packages/vue-cli-plugin-uni/lib/mp/index.js
+5
-3
packages/vue-cli-plugin-uni/lib/options.js
packages/vue-cli-plugin-uni/lib/options.js
+4
-2
packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js
.../vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js
+126
-0
packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js
...cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js
+24
-0
packages/vue-cli-plugin-uni/packages/uni-push/package.json
packages/vue-cli-plugin-uni/packages/uni-push/package.json
+29
-0
src/core/helpers/api.js
src/core/helpers/api.js
+10
-14
src/core/helpers/promise.js
src/core/helpers/promise.js
+1
-1
src/core/helpers/utils.js
src/core/helpers/utils.js
+19
-0
src/core/service/api/plugin/push.js
src/core/service/api/plugin/push.js
+102
-0
src/platforms/mp-alipay/runtime/api/index.js
src/platforms/mp-alipay/runtime/api/index.js
+108
-95
src/platforms/mp-baidu/runtime/api/index.js
src/platforms/mp-baidu/runtime/api/index.js
+28
-20
src/platforms/mp-jd/runtime/api/index.js
src/platforms/mp-jd/runtime/api/index.js
+7
-0
src/platforms/mp-kuaishou/runtime/api/index.js
src/platforms/mp-kuaishou/runtime/api/index.js
+7
-0
src/platforms/mp-lark/runtime/api/index.js
src/platforms/mp-lark/runtime/api/index.js
+7
-0
src/platforms/mp-qq/runtime/api/index.js
src/platforms/mp-qq/runtime/api/index.js
+12
-3
src/platforms/mp-toutiao/runtime/api/index.js
src/platforms/mp-toutiao/runtime/api/index.js
+12
-3
src/platforms/mp-weixin/runtime/api/index.js
src/platforms/mp-weixin/runtime/api/index.js
+7
-0
src/platforms/mp-xhs/runtime/api/index.js
src/platforms/mp-xhs/runtime/api/index.js
+7
-0
src/platforms/quickapp-webview/runtime/api/index.js
src/platforms/quickapp-webview/runtime/api/index.js
+7
-0
未找到文件。
.eslintignore
浏览文件 @
90e93c2c
...
...
@@ -20,6 +20,7 @@ packages/*/packages/mpvue-page-factory
packages/*/packages/mpvue-template-compiler
packages/*/packages/postcss-normalize-whitespace
packages/*/packages/uni-app
packages/*/packages/uni-push
packages/*/packages/uni-stat
packages/*/packages/uni-cloud
packages/*/packages/vue-loader
...
...
build/rollup.config.mp.js
浏览文件 @
90e93c2c
...
...
@@ -71,6 +71,12 @@ module.exports = {
entries
:
[{
find
:
'
@dcloudio
'
,
replacement
:
path
.
resolve
(
__dirname
,
'
../packages
'
)
},
{
find
:
'
uni-core
'
,
replacement
:
path
.
resolve
(
__dirname
,
'
../src/core
'
)
},
{
find
:
'
uni-api-protocol
'
,
replacement
:
path
.
resolve
(
__dirname
,
'
../src/core/helpers/protocol
'
)
},
{
find
:
'
uni-shared/query
'
,
replacement
:
path
.
resolve
(
__dirname
,
'
../src/shared/query.js
'
)
...
...
lib/apis.js
浏览文件 @
90e93c2c
...
...
@@ -239,7 +239,7 @@ const third = [
'
restoreGlobal
'
,
'
getSubNVueById
'
,
'
getCurrentSubNVue
'
,
'
setPageMeta
'
,
'
setPageMeta
'
,
'
onHostEventReceive
'
,
'
onNativeEventReceive
'
,
'
sendNativeEvent
'
,
...
...
@@ -257,6 +257,13 @@ const ad = [
'
createInteractiveAd
'
]
const
plugin
=
[
'
invokePushCallback
'
,
'
getPushCid
'
,
'
onPushMessage
'
,
'
offPushMessage
'
,
]
const
apis
=
[
...
base
,
...
network
,
...
...
@@ -271,7 +278,8 @@ const apis = [
...
file
,
...
canvas
,
...
third
,
...
ad
...
ad
,
...
plugin
]
module
.
exports
=
apis
packages/uni-app-plus/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
packages/uni-app-plus/dist/index.v3.js
浏览文件 @
90e93c2c
此差异已折叠。
点击以展开。
packages/uni-cli-shared/lib/index.js
浏览文件 @
90e93c2c
...
...
@@ -58,7 +58,8 @@ const {
nvueCssPreprocessOptions
,
nvueHtmlPreprocessOptions
,
getPlatformGlobal
,
getPlatformStat
getPlatformStat
,
getPlatformPush
}
=
require
(
'
./platform
'
)
module
.
exports
=
{
...
...
@@ -108,5 +109,6 @@ module.exports = {
nvueCssPreprocessOptions
,
nvueHtmlPreprocessOptions
,
getPlatformGlobal
,
getPlatformStat
getPlatformStat
,
getPlatformPush
}
packages/uni-cli-shared/lib/manifest.js
浏览文件 @
90e93c2c
...
...
@@ -85,7 +85,8 @@ function getH5Options (manifestJson) {
}
/* eslint-disable no-mixed-operators */
h5
.
template
=
h5
.
template
&&
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
h5
.
template
)
||
path
.
resolve
(
require
(
'
./util
'
).
getCLIContext
(),
'
public/index.html
'
)
h5
.
template
=
h5
.
template
&&
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
h5
.
template
)
||
path
.
resolve
(
require
(
'
./util
'
)
.
getCLIContext
(),
'
public/index.html
'
)
h5
.
devServer
=
h5
.
devServer
||
{}
...
...
@@ -97,9 +98,37 @@ function getH5Options (manifestJson) {
return
h5
}
function
isEnableUniPushV2
(
manifestJson
,
platform
)
{
if
(
!
manifestJson
)
{
manifestJson
=
getManifestJson
()
}
const
platformOptions
=
manifestJson
[
platform
]
if
(
platform
===
'
app-plus
'
)
{
const
sdkConfigs
=
platformOptions
&&
platformOptions
.
distribute
&&
platformOptions
.
distribute
.
sdkConfigs
const
unipush
=
sdkConfigs
&&
sdkConfigs
.
push
&&
sdkConfigs
.
push
.
unipush
return
(
/* eslint-disable eqeqeq */
unipush
&&
unipush
.
version
==
'
2
'
)
}
return
platformOptions
&&
platformOptions
.
unipush
&&
platformOptions
.
unipush
.
enable
===
true
}
function
isUniPushOffline
(
manifestJson
)
{
if
(
!
manifestJson
)
{
manifestJson
=
getManifestJson
()
}
const
platformOptions
=
manifestJson
[
'
app-plus
'
]
const
sdkConfigs
=
platformOptions
&&
platformOptions
.
distribute
&&
platformOptions
.
distribute
.
sdkConfigs
const
unipush
=
sdkConfigs
&&
sdkConfigs
.
push
&&
sdkConfigs
.
push
.
unipush
return
unipush
&&
unipush
.
offline
===
true
}
module
.
exports
=
{
getManifestJson
,
parseManifestJson
,
getNetworkTimeout
,
getH5Options
}
getH5Options
,
isEnableUniPushV2
,
isUniPushOffline
}
packages/uni-cli-shared/lib/platform.js
浏览文件 @
90e93c2c
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
{
isInHBuilderX
,
isInHBuilderXAlpha
,
normalizeNodeModules
}
=
require
(
'
./util
'
)
const
{
SCSS
,
SASS
}
=
require
(
'
./scss
'
)
function
getShadowCss
()
{
let
tagName
=
'
page
'
if
(
process
.
env
.
UNI_PLATFORM
===
'
h5
'
)
{
tagName
=
'
body
'
}
const
cdn
=
getShadowCdn
()
return
`
${
tagName
}
::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(
${
cdn
}
/img/shadow-grey.png)}100%{background-image:url(
${
cdn
}
/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(
${
cdn
}
/img/shadow-grey.png)}100%{background-image:url(
${
cdn
}
/img/shadow-grey.png)}}`
}
const
cdns
=
{
'
mp-weixin
'
:
1
,
'
mp-alipay
'
:
2
,
'
mp-baidu
'
:
3
,
'
mp-toutiao
'
:
4
,
'
mp-qq
'
:
5
,
'
mp-360
'
:
7
,
'
mp-dingtalk
'
:
8
,
'
mp-kuaishou
'
:
9
,
'
mp-lark
'
:
10
,
'
mp-jd
'
:
11
,
'
mp-xhs
'
:
12
,
'
quickapp-webview-huawei
'
:
200
,
'
quickapp-webview-union
'
:
201
}
function
getShadowCdn
()
{
const
index
=
cdns
[
process
.
env
.
UNI_SUB_PLATFORM
||
process
.
env
.
UNI_PLATFORM
]
||
''
return
`https://cdn
${
index
}
.dcloud.net.cn`
}
// 解决 vue-cli-service lint 时 UNI_PLATFORM 不存在
process
.
env
.
UNI_PLATFORM
=
process
.
env
.
UNI_PLATFORM
||
'
h5
'
const
uniPluginOptions
=
global
.
uniPlugin
.
options
||
{}
const
{
vueContext
:
preprocessContext
,
nvueContext
:
nvuePreprocessContext
}
=
global
.
uniPlugin
.
preprocess
// TODO 暂时保留原有导出,减少影响,后续再整理一下
module
.
exports
=
{
normalizeNodeModules
,
isInHBuilderX
,
isInHBuilderXAlpha
,
runByHBuilderX
:
isInHBuilderX
||
fs
.
existsSync
(
path
.
resolve
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
||
''
,
'
weapp-tools
'
)),
getFlexDirection
(
json
)
{
let
flexDir
=
'
column
'
if
(
json
&&
json
.
nvue
&&
json
.
nvue
[
'
flex-direction
'
])
{
flexDir
=
json
.
nvue
[
'
flex-direction
'
]
const
flexDirs
=
[
'
row
'
,
'
row-reverse
'
,
'
column
'
,
'
column-reverse
'
]
if
(
flexDirs
.
indexOf
(
flexDir
)
===
-
1
)
{
flexDir
=
'
column
'
}
}
return
flexDir
},
jsPreprocessOptions
:
{
type
:
'
js
'
,
context
:
preprocessContext
},
cssPreprocessOptions
:
{
type
:
'
css
'
,
context
:
preprocessContext
},
htmlPreprocessOptions
:
{
type
:
'
html
'
,
context
:
preprocessContext
},
nvueCssPreprocessOptions
:
{
type
:
'
css
'
,
context
:
nvuePreprocessContext
},
nvueJsPreprocessOptions
:
{
type
:
'
js
'
,
context
:
nvuePreprocessContext
},
nvueHtmlPreprocessOptions
:
{
type
:
'
html
'
,
context
:
nvuePreprocessContext
},
isSupportSubPackages
()
{
return
!!
uniPluginOptions
.
subPackages
},
getPlatforms
()
{
return
global
.
uniPlugin
.
platforms
},
getPlatformGlobal
()
{
// 目前仅mp-alipay有用
return
uniPluginOptions
.
global
},
getPlatformExts
()
{
// 小程序扩展名
return
uniPluginOptions
.
extnames
},
getPlatformProject
()
{
// 开发工具项目配置名
return
uniPluginOptions
.
project
},
getPlatformFilterTag
()
{
return
uniPluginOptions
.
filterTag
},
getMPRuntimePath
()
{
if
(
process
.
env
.
UNI_USING_VUE3
)
{
try
{
return
require
.
resolve
(
'
@dcloudio/uni-
'
+
process
.
env
.
UNI_PLATFORM
+
'
/dist/uni.mp.esm.js
'
)
}
catch
(
error
)
{
throw
new
Error
(
'
Vue3 项目暂不支持当前小程序
'
)
}
}
return
require
.
resolve
(
'
@dcloudio/uni-
'
+
process
.
env
.
UNI_PLATFORM
)
},
getPlatformVue
(
vueOptions
)
{
if
(
uniPluginOptions
.
vue
)
{
return
uniPluginOptions
.
vue
}
if
(
process
.
env
.
UNI_USING_VUE3
)
{
return
'
@dcloudio/uni-mp-vue
'
}
return
'
@dcloudio/vue-cli-plugin-uni/packages/mp-vue
'
},
getPlatformCssVars
()
{
return
uniPluginOptions
.
cssVars
||
{}
},
getPlatformCssnano
()
{
return
{
calc
:
false
,
orderedValues
:
false
,
mergeLonghand
:
false
,
mergeRules
:
false
,
cssDeclarationSorter
:
false
,
uniqueSelectors
:
false
,
// 标签排序影响头条小程序
minifySelectors
:
false
,
// 标签排序影响头条小程序
discardComments
:
false
,
discardDuplicates
:
false
// 条件编译会导致重复
}
},
getShadowCss
,
getShadowTemplate
(
colorType
=
'
grey
'
)
{
let
tagName
=
'
cover-image
'
if
(
process
.
env
.
UNI_PLATFORM
===
'
mp-toutiao
'
||
process
.
env
.
UNI_PLATFORM
===
'
mp-lark
'
||
process
.
env
.
UNI_PLATFORM
===
'
mp-xhs
'
)
{
tagName
=
'
image
'
}
return
`<
${
tagName
}
src="
${
getShadowCdn
()}
/img/shadow-
${
colorType
}
.png" style="z-index:998;position:fixed;left:0;top:0;width:100%;height:3px;"/>`
},
getPlatformScss
()
{
return
SCSS
},
getPlatformSass
()
{
return
SASS
},
getPlatformStat
()
{
if
(
!
process
.
env
.
UNI_USING_STAT
)
{
return
''
}
return
process
.
env
.
UNI_USING_STAT
===
'
2
'
?
'
import
\'
@dcloudio/uni-stat/dist/uni-cloud-stat.es.js
\'
;
'
:
'
import
\'
@dcloudio/uni-stat/dist/uni-stat.es.js
\'
;
'
},
getBabelParserOptions
()
{
return
{
sourceType
:
'
module
'
,
plugins
:
[
[
'
pipelineOperator
'
,
{
proposal
:
'
minimal
'
}],
'
doExpressions
'
,
'
optionalChaining
'
,
'
typescript
'
,
[
'
decorators
'
,
{
decoratorsBeforeExport
:
true
}],
'
classProperties
'
]
}
}
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
{
isInHBuilderX
,
isInHBuilderXAlpha
,
normalizeNodeModules
}
=
require
(
'
./util
'
)
const
{
SCSS
,
SASS
}
=
require
(
'
./scss
'
)
function
getShadowCss
()
{
let
tagName
=
'
page
'
if
(
process
.
env
.
UNI_PLATFORM
===
'
h5
'
)
{
tagName
=
'
body
'
}
const
cdn
=
getShadowCdn
()
return
`
${
tagName
}
::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(
${
cdn
}
/img/shadow-grey.png)}100%{background-image:url(
${
cdn
}
/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(
${
cdn
}
/img/shadow-grey.png)}100%{background-image:url(
${
cdn
}
/img/shadow-grey.png)}}`
}
const
cdns
=
{
'
mp-weixin
'
:
1
,
'
mp-alipay
'
:
2
,
'
mp-baidu
'
:
3
,
'
mp-toutiao
'
:
4
,
'
mp-qq
'
:
5
,
'
mp-360
'
:
7
,
'
mp-dingtalk
'
:
8
,
'
mp-kuaishou
'
:
9
,
'
mp-lark
'
:
10
,
'
mp-jd
'
:
11
,
'
mp-xhs
'
:
12
,
'
quickapp-webview-huawei
'
:
200
,
'
quickapp-webview-union
'
:
201
}
function
getShadowCdn
()
{
const
index
=
cdns
[
process
.
env
.
UNI_SUB_PLATFORM
||
process
.
env
.
UNI_PLATFORM
]
||
''
return
`https://cdn
${
index
}
.dcloud.net.cn`
}
// 解决 vue-cli-service lint 时 UNI_PLATFORM 不存在
process
.
env
.
UNI_PLATFORM
=
process
.
env
.
UNI_PLATFORM
||
'
h5
'
const
uniPluginOptions
=
global
.
uniPlugin
.
options
||
{}
const
{
vueContext
:
preprocessContext
,
nvueContext
:
nvuePreprocessContext
}
=
global
.
uniPlugin
.
preprocess
// TODO 暂时保留原有导出,减少影响,后续再整理一下
module
.
exports
=
{
normalizeNodeModules
,
isInHBuilderX
,
isInHBuilderXAlpha
,
runByHBuilderX
:
isInHBuilderX
||
fs
.
existsSync
(
path
.
resolve
(
process
.
env
.
UNI_HBUILDERX_PLUGINS
||
''
,
'
weapp-tools
'
)),
getFlexDirection
(
json
)
{
let
flexDir
=
'
column
'
if
(
json
&&
json
.
nvue
&&
json
.
nvue
[
'
flex-direction
'
])
{
flexDir
=
json
.
nvue
[
'
flex-direction
'
]
const
flexDirs
=
[
'
row
'
,
'
row-reverse
'
,
'
column
'
,
'
column-reverse
'
]
if
(
flexDirs
.
indexOf
(
flexDir
)
===
-
1
)
{
flexDir
=
'
column
'
}
}
return
flexDir
},
jsPreprocessOptions
:
{
type
:
'
js
'
,
context
:
preprocessContext
},
cssPreprocessOptions
:
{
type
:
'
css
'
,
context
:
preprocessContext
},
htmlPreprocessOptions
:
{
type
:
'
html
'
,
context
:
preprocessContext
},
nvueCssPreprocessOptions
:
{
type
:
'
css
'
,
context
:
nvuePreprocessContext
},
nvueJsPreprocessOptions
:
{
type
:
'
js
'
,
context
:
nvuePreprocessContext
},
nvueHtmlPreprocessOptions
:
{
type
:
'
html
'
,
context
:
nvuePreprocessContext
},
isSupportSubPackages
()
{
return
!!
uniPluginOptions
.
subPackages
},
getPlatforms
()
{
return
global
.
uniPlugin
.
platforms
},
getPlatformGlobal
()
{
// 目前仅mp-alipay有用
return
uniPluginOptions
.
global
},
getPlatformExts
()
{
// 小程序扩展名
return
uniPluginOptions
.
extnames
},
getPlatformProject
()
{
// 开发工具项目配置名
return
uniPluginOptions
.
project
},
getPlatformFilterTag
()
{
return
uniPluginOptions
.
filterTag
},
getMPRuntimePath
()
{
if
(
process
.
env
.
UNI_USING_VUE3
)
{
try
{
return
require
.
resolve
(
'
@dcloudio/uni-
'
+
process
.
env
.
UNI_PLATFORM
+
'
/dist/uni.mp.esm.js
'
)
}
catch
(
error
)
{
throw
new
Error
(
'
Vue3 项目暂不支持当前小程序
'
)
}
}
return
require
.
resolve
(
'
@dcloudio/uni-
'
+
process
.
env
.
UNI_PLATFORM
)
},
getPlatformVue
(
vueOptions
)
{
if
(
uniPluginOptions
.
vue
)
{
return
uniPluginOptions
.
vue
}
if
(
process
.
env
.
UNI_USING_VUE3
)
{
return
'
@dcloudio/uni-mp-vue
'
}
return
'
@dcloudio/vue-cli-plugin-uni/packages/mp-vue
'
},
getPlatformCssVars
()
{
return
uniPluginOptions
.
cssVars
||
{}
},
getPlatformCssnano
()
{
return
{
calc
:
false
,
orderedValues
:
false
,
mergeLonghand
:
false
,
mergeRules
:
false
,
cssDeclarationSorter
:
false
,
uniqueSelectors
:
false
,
// 标签排序影响头条小程序
minifySelectors
:
false
,
// 标签排序影响头条小程序
discardComments
:
false
,
discardDuplicates
:
false
// 条件编译会导致重复
}
},
getShadowCss
,
getShadowTemplate
(
colorType
=
'
grey
'
)
{
let
tagName
=
'
cover-image
'
if
(
process
.
env
.
UNI_PLATFORM
===
'
mp-toutiao
'
||
process
.
env
.
UNI_PLATFORM
===
'
mp-lark
'
||
process
.
env
.
UNI_PLATFORM
===
'
mp-xhs
'
)
{
tagName
=
'
image
'
}
return
`<
${
tagName
}
src="
${
getShadowCdn
()}
/img/shadow-
${
colorType
}
.png" style="z-index:998;position:fixed;left:0;top:0;width:100%;height:3px;"/>`
},
getPlatformScss
()
{
return
SCSS
},
getPlatformSass
()
{
return
SASS
},
getPlatformStat
()
{
if
(
!
process
.
env
.
UNI_USING_STAT
)
{
return
''
}
return
process
.
env
.
UNI_USING_STAT
===
'
2
'
?
'
import
\'
@dcloudio/uni-stat/dist/uni-cloud-stat.es.js
\'
;
'
:
'
import
\'
@dcloudio/uni-stat/dist/uni-stat.es.js
\'
;
'
},
getPlatformPush
()
{
if
(
process
.
env
.
UNI_PUSH_V2_OFFLINE
)
{
return
'
;import
\'
@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js
\'
;
'
}
else
if
(
process
.
env
.
UNI_PUSH_V2
)
{
return
'
;import
\'
@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js
\'
;
'
}
return
''
},
getBabelParserOptions
()
{
return
{
sourceType
:
'
module
'
,
plugins
:
[
[
'
pipelineOperator
'
,
{
proposal
:
'
minimal
'
}],
'
doExpressions
'
,
'
optionalChaining
'
,
'
typescript
'
,
[
'
decorators
'
,
{
decoratorsBeforeExport
:
true
}],
'
classProperties
'
]
}
}
}
packages/uni-h5/dist/index.umd.min.js
浏览文件 @
90e93c2c
此差异已折叠。
点击以展开。
packages/uni-h5/manifest.json
浏览文件 @
90e93c2c
...
...
@@ -998,5 +998,21 @@
"preloadPage"
]
]
],
"invokePushCallback"
:
[
"/core/service/api/plugin/push.js"
,
[]
],
"getPushCid"
:
[
"/core/service/api/plugin/push.js"
,
[]
],
"onPushMessage"
:
[
"/core/service/api/plugin/push.js"
,
[]
],
"offPushMessage"
:
[
"/core/service/api/plugin/push.js"
,
[]
]
}
\ No newline at end of file
packages/uni-mp-alipay/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -1440,87 +1440,215 @@ function createMediaQueryObserver () {
return
mediaQueryObserver
}
function
startGyroscope
(
params
)
{
if
(
hasOwn
(
params
,
'
interval
'
))
{
console
.
warn
(
'
支付宝小程序 startGyroscope暂不支持interval
'
);
}
params
.
success
&&
params
.
success
({
errMsg
:
'
startGyroscope:ok
'
});
params
.
complete
&&
params
.
complete
({
errMsg
:
'
startGyroscope:ok
'
});
}
function
createExecCallback
(
execCallback
)
{
return
function
wrapperExecCallback
(
res
)
{
this
.
actions
.
forEach
((
action
,
index
)
=>
{
(
action
.
_$callbacks
||
[]).
forEach
(
callback
=>
{
callback
(
res
[
index
]);
});
});
if
(
isFn
(
execCallback
))
{
execCallback
(
res
);
}
}
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
addCallback
(
callback
)
{
if
(
isFn
(
callback
))
{
const
action
=
this
.
actions
[
this
.
actions
.
length
-
1
];
if
(
action
)
{
(
action
.
_$callbacks
||
(
action
.
_$callbacks
=
[])).
push
(
callback
);
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
function
createSelectorQuery
()
{
const
query
=
my
.
createSelectorQuery
();
const
oldExec
=
query
.
exec
;
const
oldScrollOffset
=
query
.
scrollOffset
;
const
oldBoundingClientRect
=
query
.
boundingClientRect
;
query
.
exec
=
function
exec
(
callback
)
{
return
oldExec
.
call
(
this
,
createExecCallback
(
callback
).
bind
(
this
))
};
query
.
scrollOffset
=
function
scrollOffset
(
callback
)
{
const
ret
=
oldScrollOffset
.
call
(
this
);
addCallback
.
call
(
this
,
callback
);
return
ret
};
query
.
boundingClientRect
=
function
boundingClientRect
(
callback
)
{
const
ret
=
oldBoundingClientRect
.
call
(
this
);
addCallback
.
call
(
this
,
callback
);
return
ret
};
if
(
!
query
.
fields
)
{
query
.
fields
=
function
({
rect
,
size
,
scrollOffset
}
=
{},
callback
)
{
if
(
rect
||
size
)
{
this
.
boundingClientRect
();
}
if
(
scrollOffset
)
{
this
.
scrollOffset
();
}
addCallback
.
call
(
this
,
callback
);
return
this
};
}
if
(
!
query
.
in
)
{
query
.
in
=
function
()
{
return
this
};
}
return
query
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
function
createIntersectionObserver
(
component
,
options
)
{
if
(
options
&&
options
.
observeAll
)
{
options
.
selectAll
=
options
.
observeAll
;
delete
options
.
observeAll
;
}
return
my
.
createIntersectionObserver
(
options
)
function
startGyroscope
(
params
)
{
if
(
hasOwn
(
params
,
'
interval
'
))
{
console
.
warn
(
'
支付宝小程序 startGyroscope暂不支持interval
'
);
}
params
.
success
&&
params
.
success
({
errMsg
:
'
startGyroscope:ok
'
});
params
.
complete
&&
params
.
complete
({
errMsg
:
'
startGyroscope:ok
'
});
}
function
createExecCallback
(
execCallback
)
{
return
function
wrapperExecCallback
(
res
)
{
this
.
actions
.
forEach
((
action
,
index
)
=>
{
(
action
.
_$callbacks
||
[]).
forEach
(
callback
=>
{
callback
(
res
[
index
]);
});
});
if
(
isFn
(
execCallback
))
{
execCallback
(
res
);
}
}
}
function
addCallback
(
callback
)
{
if
(
isFn
(
callback
))
{
const
action
=
this
.
actions
[
this
.
actions
.
length
-
1
];
if
(
action
)
{
(
action
.
_$callbacks
||
(
action
.
_$callbacks
=
[])).
push
(
callback
);
}
}
}
function
createSelectorQuery
()
{
const
query
=
my
.
createSelectorQuery
();
const
oldExec
=
query
.
exec
;
const
oldScrollOffset
=
query
.
scrollOffset
;
const
oldBoundingClientRect
=
query
.
boundingClientRect
;
query
.
exec
=
function
exec
(
callback
)
{
return
oldExec
.
call
(
this
,
createExecCallback
(
callback
).
bind
(
this
))
};
query
.
scrollOffset
=
function
scrollOffset
(
callback
)
{
const
ret
=
oldScrollOffset
.
call
(
this
);
addCallback
.
call
(
this
,
callback
);
return
ret
};
query
.
boundingClientRect
=
function
boundingClientRect
(
callback
)
{
const
ret
=
oldBoundingClientRect
.
call
(
this
);
addCallback
.
call
(
this
,
callback
);
return
ret
};
if
(
!
query
.
fields
)
{
query
.
fields
=
function
({
rect
,
size
,
scrollOffset
}
=
{},
callback
)
{
if
(
rect
||
size
)
{
this
.
boundingClientRect
();
}
if
(
scrollOffset
)
{
this
.
scrollOffset
();
}
addCallback
.
call
(
this
,
callback
);
return
this
};
}
if
(
!
query
.
in
)
{
query
.
in
=
function
()
{
return
this
};
}
return
query
}
function
createIntersectionObserver
(
component
,
options
)
{
if
(
options
&&
options
.
observeAll
)
{
options
.
selectAll
=
options
.
observeAll
;
delete
options
.
observeAll
;
}
return
my
.
createIntersectionObserver
(
options
)
}
var
api
=
/*#__PURE__*/
Object
.
freeze
({
...
...
@@ -1531,7 +1659,11 @@ var api = /*#__PURE__*/Object.freeze({
createMediaQueryObserver
:
createMediaQueryObserver
,
setStorageSync
:
setStorageSync
,
getStorageSync
:
getStorageSync
,
removeStorageSync
:
removeStorageSync
removeStorageSync
:
removeStorageSync
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
PAGE_EVENT_HOOKS
=
[
...
...
packages/uni-mp-baidu/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -1093,28 +1093,156 @@ function createMediaQueryObserver () {
return
mediaQueryObserver
}
function
requestPayment
(
params
)
{
let
parseError
=
false
;
if
(
typeof
params
.
orderInfo
===
'
string
'
)
{
try
{
params
.
orderInfo
=
JSON
.
parse
(
params
.
orderInfo
);
}
catch
(
e
)
{
parseError
=
true
;
}
}
if
(
parseError
)
{
params
.
fail
&&
params
.
fail
({
errMsg
:
'
requestPayment:fail 参数 orderInfo 数据结构不正确,参考:https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
'
});
}
else
{
swan
.
requestPolymerPayment
(
params
);
}
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
function
requestPayment
(
params
)
{
let
parseError
=
false
;
if
(
typeof
params
.
orderInfo
===
'
string
'
)
{
try
{
params
.
orderInfo
=
JSON
.
parse
(
params
.
orderInfo
);
}
catch
(
e
)
{
parseError
=
true
;
}
}
if
(
parseError
)
{
params
.
fail
&&
params
.
fail
({
errMsg
:
'
requestPayment:fail 参数 orderInfo 数据结构不正确,参考:https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
'
});
}
else
{
swan
.
requestPolymerPayment
(
params
);
}
}
var
api
=
/*#__PURE__*/
Object
.
freeze
({
__proto__
:
null
,
requestPayment
:
requestPayment
,
createMediaQueryObserver
:
createMediaQueryObserver
createMediaQueryObserver
:
createMediaQueryObserver
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
MPPage
=
Page
;
...
...
packages/uni-mp-jd/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -688,8 +688,136 @@ var eventApi = /*#__PURE__*/Object.freeze({
$emit
:
$emit
});
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
var
api
=
/*#__PURE__*/
Object
.
freeze
({
__proto__
:
null
__proto__
:
null
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
MPPage
=
Page
;
...
...
packages/uni-mp-kuaishou/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -888,8 +888,136 @@ var eventApi = /*#__PURE__*/Object.freeze({
$emit
:
$emit
});
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
var
api
=
/*#__PURE__*/
Object
.
freeze
({
__proto__
:
null
__proto__
:
null
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
MPPage
=
Page
;
...
...
packages/uni-mp-lark/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -938,8 +938,136 @@ var eventApi = /*#__PURE__*/Object.freeze({
$emit
:
$emit
});
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
var
api
=
/*#__PURE__*/
Object
.
freeze
({
__proto__
:
null
__proto__
:
null
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
MPPage
=
Page
;
...
...
packages/uni-mp-qq/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -1048,9 +1048,137 @@ function createMediaQueryObserver () {
return
mediaQueryObserver
}
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
var
api
=
/*#__PURE__*/
Object
.
freeze
({
__proto__
:
null
,
createMediaQueryObserver
:
createMediaQueryObserver
createMediaQueryObserver
:
createMediaQueryObserver
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
MPPage
=
Page
;
...
...
packages/uni-mp-toutiao/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -1140,9 +1140,137 @@ function createMediaQueryObserver () {
return
mediaQueryObserver
}
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
var
api
=
/*#__PURE__*/
Object
.
freeze
({
__proto__
:
null
,
createMediaQueryObserver
:
createMediaQueryObserver
createMediaQueryObserver
:
createMediaQueryObserver
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
MPPage
=
Page
;
...
...
packages/uni-mp-weixin/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -789,8 +789,136 @@ var eventApi = /*#__PURE__*/Object.freeze({
$emit
:
$emit
});
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
var
api
=
/*#__PURE__*/
Object
.
freeze
({
__proto__
:
null
__proto__
:
null
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
MPPage
=
Page
;
...
...
packages/uni-mp-xhs/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -689,8 +689,136 @@ var eventApi = /*#__PURE__*/Object.freeze({
$emit
:
$emit
});
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
var
api
=
/*#__PURE__*/
Object
.
freeze
({
__proto__
:
null
__proto__
:
null
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
MPPage
=
Page
;
...
...
packages/uni-quickapp-native/dist/vue.dev.js
浏览文件 @
90e93c2c
此差异已折叠。
点击以展开。
packages/uni-quickapp-native/dist/vue.prod.js
浏览文件 @
90e93c2c
此差异已折叠。
点击以展开。
packages/uni-quickapp-webview/dist/index.js
浏览文件 @
90e93c2c
...
...
@@ -314,7 +314,7 @@ const promiseInterceptor = {
};
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
;
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -855,8 +855,136 @@ var eventApi = /*#__PURE__*/Object.freeze({
$emit
:
$emit
});
/**
* 框架内 try-catch
*/
/**
* 开发者 try-catch
*/
function
tryCatch
(
fn
)
{
return
function
()
{
try
{
return
fn
.
apply
(
fn
,
arguments
)
}
catch
(
e
)
{
// TODO
console
.
error
(
e
);
}
}
}
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
params
)
{
const
param
=
params
[
name
];
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
);
delete
params
[
name
];
}
}
return
apiCallbacks
}
let
cid
;
let
cidErrMsg
;
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
;
cidErrMsg
=
args
.
errMsg
;
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
);
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
});
});
}
}
const
getPushCidCallbacks
=
[];
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
);
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFn
(
success
);
const
hasFail
=
isFn
(
fail
);
const
hasComplete
=
isFn
(
complete
);
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
);
}
};
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
;
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
);
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
);
}
}
};
var
api
=
/*#__PURE__*/
Object
.
freeze
({
__proto__
:
null
__proto__
:
null
,
getPushCid
:
getPushCid
,
onPushMessage
:
onPushMessage
,
offPushMessage
:
offPushMessage
,
invokePushCallback
:
invokePushCallback
});
const
MPPage
=
Page
;
...
...
packages/vue-cli-plugin-uni/lib/app-plus/index.js
浏览文件 @
90e93c2c
...
...
@@ -2,8 +2,9 @@ const path = require('path')
const
webpack
=
require
(
'
webpack
'
)
const
{
getMainEntry
,
getPlatformStat
getMainEntry
,
getPlatformStat
,
getPlatformPush
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
vueLoader
=
require
(
'
@dcloudio/uni-cli-shared/lib/vue-loader
'
)
...
...
@@ -60,6 +61,7 @@ const v3 = {
const
isAppView
=
!!
vueOptions
.
pluginOptions
[
'
uni-app-plus
'
].
view
const
statCode
=
getPlatformStat
()
const
pushCode
=
getPlatformPush
()
const
beforeCode
=
'
import
\'
uni-pages
\'
;
'
...
...
@@ -154,7 +156,7 @@ const v3 = {
options
:
{
compiler
:
vueLoader
.
compiler
,
before
:
[
beforeCode
+
require
(
'
../util
'
).
getAutomatorCode
()
+
statCode
+
beforeCode
+
require
(
'
../util
'
).
getAutomatorCode
()
+
statCode
+
pushCode
+
getGlobalUsingComponentsCode
()
]
}
...
...
packages/vue-cli-plugin-uni/lib/env.js
浏览文件 @
90e93c2c
...
...
@@ -19,7 +19,13 @@ if (process.env.UNI_INPUT_DIR && process.env.UNI_INPUT_DIR.indexOf('./') === 0)
}
process
.
env
.
UNI_INPUT_DIR
=
process
.
env
.
UNI_INPUT_DIR
||
path
.
resolve
(
process
.
cwd
(),
defaultInputDir
)
const
manifestJsonObj
=
require
(
'
@dcloudio/uni-cli-shared/lib/manifest
'
).
getManifestJson
()
const
{
getManifestJson
,
isEnableUniPushV2
,
isUniPushOffline
}
=
require
(
'
@dcloudio/uni-cli-shared/lib/manifest
'
)
const
manifestJsonObj
=
getManifestJson
()
process
.
env
.
UNI_APP_ID
=
manifestJsonObj
.
appid
||
''
process
.
env
.
UNI_APP_NAME
=
manifestJsonObj
.
name
||
''
...
...
@@ -32,6 +38,13 @@ if (process.env.UNI_PLATFORM.indexOf('mp-') === 0) {
process
.
env
.
UNI_USING_VUE3_OPTIONS_API
=
true
}
}
// v2 uni-push
if
(
isEnableUniPushV2
(
manifestJsonObj
,
process
.
env
.
UNI_PLATFORM
))
{
process
.
env
.
UNI_PUSH_V2
=
true
if
(
process
.
env
.
UNI_PLATFORM
===
'
app-plus
'
&&
isUniPushOffline
(
manifestJsonObj
))
{
process
.
env
.
UNI_PUSH_V2_OFFLINE
=
true
}
}
// 初始化全局插件对象
global
.
uniPlugin
=
require
(
'
@dcloudio/uni-cli-shared/lib/plugin
'
).
init
()
...
...
packages/vue-cli-plugin-uni/lib/h5/index.js
浏览文件 @
90e93c2c
...
...
@@ -4,8 +4,9 @@ const webpack = require('webpack')
const
{
getMainEntry
,
getH5Options
,
getPlatformStat
getH5Options
,
getPlatformStat
,
getPlatformPush
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
{
...
...
@@ -93,7 +94,7 @@ module.exports = {
let
useBuiltIns
=
'
usage
'
const
statCode
=
getPlatformStat
()
const
pushCode
=
getPlatformPush
()
try
{
const
babelConfig
=
require
(
path
.
resolve
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
babel.config.js
'
))
useBuiltIns
=
babelConfig
.
presets
[
0
][
1
].
useBuiltIns
...
...
@@ -117,7 +118,7 @@ module.exports = {
loader
:
path
.
resolve
(
__dirname
,
'
../../packages/wrap-loader
'
),
options
:
{
before
:
[
beforeCode
+
require
(
'
../util
'
).
getAutomatorCode
()
+
statCode
+
beforeCode
+
require
(
'
../util
'
).
getAutomatorCode
()
+
statCode
+
pushCode
+
getGlobalUsingComponentsCode
()
]
}
...
...
packages/vue-cli-plugin-uni/lib/mp/index.js
浏览文件 @
90e93c2c
...
...
@@ -6,8 +6,9 @@ const {
getMainEntry
,
normalizePath
,
getPlatformExts
,
getPlatformCssnano
,
getPlatformStat
getPlatformCssnano
,
getPlatformStat
,
getPlatformPush
}
=
require
(
'
@dcloudio/uni-cli-shared
'
)
const
WebpackUniAppPlugin
=
require
(
'
../../packages/webpack-uni-app-loader/plugin/index
'
)
...
...
@@ -166,6 +167,7 @@ module.exports = {
parseEntry
()
const
statCode
=
getPlatformStat
()
const
pushCode
=
getPlatformPush
()
let
beforeCode
=
'
import
\'
uni-pages
\'
;
'
...
...
@@ -236,7 +238,7 @@ module.exports = {
loader
:
path
.
resolve
(
__dirname
,
'
../../packages/wrap-loader
'
),
options
:
{
before
:
[
beforeCode
+
require
(
'
../util
'
).
getAutomatorCode
()
+
statCode
beforeCode
+
require
(
'
../util
'
).
getAutomatorCode
()
+
statCode
+
pushCode
]
}
},
{
...
...
packages/vue-cli-plugin-uni/lib/options.js
浏览文件 @
90e93c2c
...
...
@@ -23,10 +23,12 @@ module.exports = function initOptions (options) {
options
.
transpileDependencies
.
push
(
genTranspileDepRegex
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
node_modules
'
)))
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-
'
+
process
.
env
.
UNI_PLATFORM
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-i18n
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-stat
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-stat
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-push
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-app
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-cloud
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-stat
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-stat
'
)
options
.
transpileDependencies
.
push
(
'
@dcloudio/vue-cli-plugin-uni/packages/uni-push
'
)
if
(
process
.
env
.
UNI_PLATFORM
!==
'
mp-weixin
'
)
{
// mp runtime
options
.
transpileDependencies
.
push
(
'
@dcloudio/uni-mp-weixin
'
)
...
...
packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js
0 → 100644
浏览文件 @
90e93c2c
此差异已折叠。
点击以展开。
packages/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js
0 → 100644
浏览文件 @
90e93c2c
Promise
.
resolve
().
then
(()
=>
{
const
info
=
plus
.
push
.
getClientInfo
();
if
(
info
.
clientid
)
{
// @ts-expect-error
uni
.
invokePushCallback
({
type
:
'
clientId
'
,
cid
:
info
.
clientid
,
});
}
plus
.
push
.
addEventListener
(
'
click
'
,
(
result
)
=>
{
// @ts-expect-error
uni
.
invokePushCallback
({
type
:
'
click
'
,
message
:
result
,
});
});
plus
.
push
.
addEventListener
(
'
receive
'
,
(
result
)
=>
{
// @ts-expect-error
uni
.
invokePushCallback
({
type
:
'
pushMsg
'
,
message
:
result
,
});
});
});
packages/vue-cli-plugin-uni/packages/uni-push/package.json
0 → 100644
浏览文件 @
90e93c2c
{
"name"
:
"@dcloudio/uni-push"
,
"version"
:
"3.0.0-alpha-3040620220415003"
,
"description"
:
"@dcloudio/uni-push"
,
"main"
:
"lib/uni-push.js"
,
"module"
:
"lib/uni-push.js"
,
"files"
:
[
"dist"
,
"lib"
],
"sideEffects"
:
false
,
"repository"
:
{
"type"
:
"git"
,
"url"
:
"git+https://github.com/dcloudio/uni-app.git"
,
"directory"
:
"packages/uni-push"
},
"license"
:
"Apache-2.0"
,
"bugs"
:
{
"url"
:
"https://github.com/dcloudio/uni-app/issues"
},
"gitHead"
:
"33e807d66e1fe47e2ee08ad9c59247e37b8884da"
,
"dependencies"
:
{
"@dcloudio/uni-cli-shared"
:
"3.0.0-alpha-3040620220415003"
,
"debug"
:
"^4.3.3"
},
"devDependencies"
:
{
"@types/debug"
:
"^4.1.7"
}
}
src/core/helpers/api.js
浏览文件 @
90e93c2c
...
...
@@ -4,7 +4,6 @@ import {
}
from
'
uni-shared
'
import
{
tryCatch
,
tryCatchFramework
}
from
'
./catch
'
...
...
@@ -13,6 +12,9 @@ import {
isSyncApi
,
isCallbackApi
}
from
'
./promise
'
import
{
getApiCallbacks
}
from
'
./utils
'
import
protocol
from
'
uni-api-protocol
'
...
...
@@ -133,21 +135,12 @@ function createApiCallback (apiName, params = {}, extras = {}) {
}
params
=
Object
.
assign
({},
params
)
const
apiCallbacks
=
{}
for
(
const
name
in
params
)
{
const
param
=
params
[
name
]
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
)
delete
params
[
name
]
}
}
const
{
success
,
fail
,
cancel
,
complete
}
=
apiCallbacks
}
=
getApiCallbacks
(
params
)
const
hasSuccess
=
isFn
(
success
)
const
hasFail
=
isFn
(
fail
)
...
...
@@ -292,9 +285,11 @@ function wrapperExtras (name, extras) {
isFn
(
protocolOptions
.
beforeSuccess
)
&&
(
extras
.
beforeSuccess
=
protocolOptions
.
beforeSuccess
)
}
}
// 部分 API 直接实现
const
unwrappers
=
[
'
getPushCid
'
,
'
onPushMessage
'
,
'
offPushMessage
'
]
export
function
wrapper
(
name
,
invokeMethod
,
extras
=
{})
{
if
(
!
isFn
(
invokeMethod
))
{
if
(
unwrappers
.
indexOf
(
name
)
>
-
1
||
!
isFn
(
invokeMethod
))
{
return
invokeMethod
}
wrapperExtras
(
name
,
extras
)
...
...
@@ -305,7 +300,8 @@ export function wrapper (name, invokeMethod, extras = {}) {
}
}
else
if
(
isCallbackApi
(
name
))
{
if
(
validateParams
(
name
,
args
,
-
1
))
{
return
invokeMethod
((
name
.
startsWith
(
'
off
'
)
?
getKeepAliveApiCallback
:
createKeepAliveApiCallback
)(
name
,
args
[
0
]))
return
invokeMethod
((
name
.
startsWith
(
'
off
'
)
?
getKeepAliveApiCallback
:
createKeepAliveApiCallback
)(
name
,
args
[
0
]))
}
}
else
{
let
argsObj
=
{}
...
...
@@ -333,4 +329,4 @@ export function wrapper (name, invokeMethod, extras = {}) {
}
}
}
}
}
src/core/helpers/promise.js
浏览文件 @
90e93c2c
...
...
@@ -8,7 +8,7 @@ import {
}
from
'
./interceptor
'
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale/
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale
|invokePushCallback
/
const
CONTEXT_API_RE
=
/^create|Manager$/
...
...
src/core/helpers/utils.js
0 → 100644
浏览文件 @
90e93c2c
import
{
isFn
}
from
'
uni-shared
'
import
{
tryCatch
}
from
'
./catch
'
export
function
getApiCallbacks
(
params
)
{
const
apiCallbacks
=
{}
for
(
const
name
in
params
)
{
const
param
=
params
[
name
]
if
(
isFn
(
param
))
{
apiCallbacks
[
name
]
=
tryCatch
(
param
)
delete
params
[
name
]
}
}
return
apiCallbacks
}
src/core/service/api/plugin/push.js
0 → 100644
浏览文件 @
90e93c2c
import
{
isFn
,
isPlainObject
}
from
'
uni-shared
'
import
{
getApiCallbacks
}
from
'
uni-helpers/utils
'
let
cid
let
cidErrMsg
function
normalizePushMessage
(
message
)
{
try
{
return
JSON
.
parse
(
message
)
}
catch
(
e
)
{}
return
message
}
export
function
invokePushCallback
(
args
)
{
if
(
args
.
type
===
'
clientId
'
)
{
cid
=
args
.
cid
cidErrMsg
=
args
.
errMsg
invokeGetPushCidCallbacks
(
cid
,
args
.
errMsg
)
}
else
if
(
args
.
type
===
'
pushMsg
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
receive
'
,
data
:
normalizePushMessage
(
args
.
message
)
})
})
}
else
if
(
args
.
type
===
'
click
'
)
{
onPushMessageCallbacks
.
forEach
((
callback
)
=>
{
callback
({
type
:
'
click
'
,
data
:
normalizePushMessage
(
args
.
message
)
})
})
}
}
const
getPushCidCallbacks
=
[]
function
invokeGetPushCidCallbacks
(
cid
,
errMsg
)
{
getPushCidCallbacks
.
forEach
((
callback
)
=>
{
callback
(
cid
,
errMsg
)
})
getPushCidCallbacks
.
length
=
0
}
export
function
getPushCid
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{}
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
)
const
hasSuccess
=
isFn
(
success
)
const
hasFail
=
isFn
(
fail
)
const
hasComplete
=
isFn
(
complete
)
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushCid:ok
'
,
cid
}
hasSuccess
&&
success
(
res
)
}
else
{
res
=
{
errMsg
:
'
getPushCid:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
}
hasFail
&&
fail
(
res
)
}
hasComplete
&&
complete
(
res
)
})
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
))
}
}
const
onPushMessageCallbacks
=
[]
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
export
const
onPushMessage
=
(
fn
)
=>
{
if
(
onPushMessageCallbacks
.
indexOf
(
fn
)
===
-
1
)
{
onPushMessageCallbacks
.
push
(
fn
)
}
}
export
const
offPushMessage
=
(
fn
)
=>
{
if
(
!
fn
)
{
onPushMessageCallbacks
.
length
=
0
}
else
{
const
index
=
onPushMessageCallbacks
.
indexOf
(
fn
)
if
(
index
>
-
1
)
{
onPushMessageCallbacks
.
splice
(
index
,
1
)
}
}
}
src/platforms/mp-alipay/runtime/api/index.js
浏览文件 @
90e93c2c
import
createMediaQueryObserver
from
'
../../../mp-weixin/helpers/create-media-query-observer
'
import
{
isFn
,
hasOwn
}
from
'
uni-shared
'
export
{
setStorageSync
,
getStorageSync
,
removeStorageSync
}
from
'
../../helpers/storage
'
export
function
startGyroscope
(
params
)
{
if
(
hasOwn
(
params
,
'
interval
'
))
{
console
.
warn
(
'
支付宝小程序 startGyroscope暂不支持interval
'
)
}
params
.
success
&&
params
.
success
({
errMsg
:
'
startGyroscope:ok
'
})
params
.
complete
&&
params
.
complete
({
errMsg
:
'
startGyroscope:ok
'
})
import
createMediaQueryObserver
from
'
../../../mp-weixin/helpers/create-media-query-observer
'
import
{
isFn
,
hasOwn
}
from
'
uni-shared
'
export
{
setStorageSync
,
getStorageSync
,
removeStorageSync
}
from
'
../../helpers/storage
'
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
export
function
startGyroscope
(
params
)
{
if
(
hasOwn
(
params
,
'
interval
'
))
{
console
.
warn
(
'
支付宝小程序 startGyroscope暂不支持interval
'
)
}
params
.
success
&&
params
.
success
({
errMsg
:
'
startGyroscope:ok
'
})
params
.
complete
&&
params
.
complete
({
errMsg
:
'
startGyroscope:ok
'
})
}
function
createExecCallback
(
execCallback
)
{
return
function
wrapperExecCallback
(
res
)
{
this
.
actions
.
forEach
((
action
,
index
)
=>
{
(
action
.
_$callbacks
||
[]).
forEach
(
callback
=>
{
callback
(
res
[
index
])
})
})
if
(
isFn
(
execCallback
))
{
execCallback
(
res
)
}
}
}
function
addCallback
(
callback
)
{
if
(
isFn
(
callback
))
{
const
action
=
this
.
actions
[
this
.
actions
.
length
-
1
]
if
(
action
)
{
(
action
.
_$callbacks
||
(
action
.
_$callbacks
=
[])).
push
(
callback
)
}
}
}
export
function
createSelectorQuery
()
{
const
query
=
my
.
createSelectorQuery
()
const
oldExec
=
query
.
exec
const
oldScrollOffset
=
query
.
scrollOffset
const
oldBoundingClientRect
=
query
.
boundingClientRect
query
.
exec
=
function
exec
(
callback
)
{
return
oldExec
.
call
(
this
,
createExecCallback
(
callback
).
bind
(
this
))
}
query
.
scrollOffset
=
function
scrollOffset
(
callback
)
{
const
ret
=
oldScrollOffset
.
call
(
this
)
addCallback
.
call
(
this
,
callback
)
return
ret
}
query
.
boundingClientRect
=
function
boundingClientRect
(
callback
)
{
const
ret
=
oldBoundingClientRect
.
call
(
this
)
addCallback
.
call
(
this
,
callback
)
return
ret
}
if
(
!
query
.
fields
)
{
query
.
fields
=
function
({
rect
,
size
,
scrollOffset
}
=
{},
callback
)
{
if
(
rect
||
size
)
{
this
.
boundingClientRect
()
}
if
(
scrollOffset
)
{
this
.
scrollOffset
()
}
addCallback
.
call
(
this
,
callback
)
return
this
}
}
if
(
!
query
.
in
)
{
query
.
in
=
function
()
{
return
this
}
}
return
query
}
export
function
createIntersectionObserver
(
component
,
options
)
{
if
(
options
&&
options
.
observeAll
)
{
options
.
selectAll
=
options
.
observeAll
delete
options
.
observeAll
}
return
my
.
createIntersectionObserver
(
options
)
}
export
{
createMediaQueryObserver
}
function
createExecCallback
(
execCallback
)
{
return
function
wrapperExecCallback
(
res
)
{
this
.
actions
.
forEach
((
action
,
index
)
=>
{
(
action
.
_$callbacks
||
[]).
forEach
(
callback
=>
{
callback
(
res
[
index
])
})
})
if
(
isFn
(
execCallback
))
{
execCallback
(
res
)
}
}
}
function
addCallback
(
callback
)
{
if
(
isFn
(
callback
))
{
const
action
=
this
.
actions
[
this
.
actions
.
length
-
1
]
if
(
action
)
{
(
action
.
_$callbacks
||
(
action
.
_$callbacks
=
[])).
push
(
callback
)
}
}
}
export
function
createSelectorQuery
()
{
const
query
=
my
.
createSelectorQuery
()
const
oldExec
=
query
.
exec
const
oldScrollOffset
=
query
.
scrollOffset
const
oldBoundingClientRect
=
query
.
boundingClientRect
query
.
exec
=
function
exec
(
callback
)
{
return
oldExec
.
call
(
this
,
createExecCallback
(
callback
).
bind
(
this
))
}
query
.
scrollOffset
=
function
scrollOffset
(
callback
)
{
const
ret
=
oldScrollOffset
.
call
(
this
)
addCallback
.
call
(
this
,
callback
)
return
ret
}
query
.
boundingClientRect
=
function
boundingClientRect
(
callback
)
{
const
ret
=
oldBoundingClientRect
.
call
(
this
)
addCallback
.
call
(
this
,
callback
)
return
ret
}
if
(
!
query
.
fields
)
{
query
.
fields
=
function
({
rect
,
size
,
scrollOffset
}
=
{},
callback
)
{
if
(
rect
||
size
)
{
this
.
boundingClientRect
()
}
if
(
scrollOffset
)
{
this
.
scrollOffset
()
}
addCallback
.
call
(
this
,
callback
)
return
this
}
}
if
(
!
query
.
in
)
{
query
.
in
=
function
()
{
return
this
}
}
return
query
}
export
function
createIntersectionObserver
(
component
,
options
)
{
if
(
options
&&
options
.
observeAll
)
{
options
.
selectAll
=
options
.
observeAll
delete
options
.
observeAll
}
return
my
.
createIntersectionObserver
(
options
)
}
export
{
createMediaQueryObserver
}
src/platforms/mp-baidu/runtime/api/index.js
浏览文件 @
90e93c2c
import
createMediaQueryObserver
from
'
../../../mp-weixin/helpers/create-media-query-observer
'
export
function
requestPayment
(
params
)
{
let
parseError
=
false
if
(
typeof
params
.
orderInfo
===
'
string
'
)
{
try
{
params
.
orderInfo
=
JSON
.
parse
(
params
.
orderInfo
)
}
catch
(
e
)
{
parseError
=
true
}
}
if
(
parseError
)
{
params
.
fail
&&
params
.
fail
({
errMsg
:
'
requestPayment:fail 参数 orderInfo 数据结构不正确,参考:https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
'
})
}
else
{
swan
.
requestPolymerPayment
(
params
)
}
import
createMediaQueryObserver
from
'
../../../mp-weixin/helpers/create-media-query-observer
'
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
export
function
requestPayment
(
params
)
{
let
parseError
=
false
if
(
typeof
params
.
orderInfo
===
'
string
'
)
{
try
{
params
.
orderInfo
=
JSON
.
parse
(
params
.
orderInfo
)
}
catch
(
e
)
{
parseError
=
true
}
}
if
(
parseError
)
{
params
.
fail
&&
params
.
fail
({
errMsg
:
'
requestPayment:fail 参数 orderInfo 数据结构不正确,参考:https://uniapp.dcloud.io/api/plugins/payment?id=orderinfo
'
})
}
else
{
swan
.
requestPolymerPayment
(
params
)
}
}
export
{
createMediaQueryObserver
}
export
{
createMediaQueryObserver
}
src/platforms/mp-jd/runtime/api/index.js
浏览文件 @
90e93c2c
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
src/platforms/mp-kuaishou/runtime/api/index.js
浏览文件 @
90e93c2c
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
src/platforms/mp-lark/runtime/api/index.js
浏览文件 @
90e93c2c
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
src/platforms/mp-qq/runtime/api/index.js
浏览文件 @
90e93c2c
import
createMediaQueryObserver
from
'
../../../mp-weixin/helpers/create-media-query-observer
'
export
{
createMediaQueryObserver
}
import
createMediaQueryObserver
from
'
../../../mp-weixin/helpers/create-media-query-observer
'
export
{
createMediaQueryObserver
}
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
src/platforms/mp-toutiao/runtime/api/index.js
浏览文件 @
90e93c2c
import
createMediaQueryObserver
from
'
../../../mp-weixin/helpers/create-media-query-observer
'
export
{
createMediaQueryObserver
}
import
createMediaQueryObserver
from
'
../../../mp-weixin/helpers/create-media-query-observer
'
export
{
createMediaQueryObserver
}
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
src/platforms/mp-weixin/runtime/api/index.js
浏览文件 @
90e93c2c
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
src/platforms/mp-xhs/runtime/api/index.js
浏览文件 @
90e93c2c
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
src/platforms/quickapp-webview/runtime/api/index.js
浏览文件 @
90e93c2c
export
{
getPushCid
,
onPushMessage
,
offPushMessage
,
invokePushCallback
}
from
'
uni-core/service/api/plugin/push
'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录