提交 90e93c2c 编写于 作者: fxy060608's avatar fxy060608

feat(push): v2

上级 1b5464da
......@@ -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
......
......@@ -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')
......
......@@ -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
......@@ -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$/;
......
......@@ -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
}
......@@ -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
}
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'
]
}
}
}
......@@ -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
......@@ -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 = [
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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()
]
}
......
......@@ -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()
......
......@@ -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()
]
}
......
......@@ -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
]
}
}, {
......
......@@ -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')
......
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,
});
});
});
{
"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"
}
}
......@@ -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 = {}) {
}
}
}
}
}
......@@ -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$/
......
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
}
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)
}
}
}
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 }
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 }
export {
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback
}
from 'uni-core/service/api/plugin/push'
export {
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback
}
from 'uni-core/service/api/plugin/push'
export {
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback
}
from 'uni-core/service/api/plugin/push'
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'
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'
export {
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback
}
from 'uni-core/service/api/plugin/push'
export {
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback
}
from 'uni-core/service/api/plugin/push'
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.
先完成此消息的编辑!
想要评论请 注册