From 6696b612b1d870283fd1f1bd95f7d4b1dff0403a Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 7 Dec 2018 19:45:02 +0800 Subject: [PATCH] update mp-runtime --- build/rollup.config.js | 2 +- packages/uni-mp-alipay/dist/index.js | 75 +++++++++++++++++++ packages/uni-mp-alipay/package.json | 2 +- packages/uni-mp-baidu/dist/index.js | 75 +++++++++++++++++++ packages/uni-mp-baidu/package.json | 2 +- packages/uni-mp-weixin/dist/index.js | 75 +++++++++++++++++++ packages/uni-mp-weixin/package.json | 2 +- src/core/runtime/base.js | 28 +++++++ src/core/{uni.js => runtime/index.js} | 22 +++++- src/core/runtime/todo.js | 32 ++++++++ .../mp-alipay/service/api/providers.js | 6 ++ .../mp-baidu/service/api/providers.js | 6 ++ .../mp-weixin/service/api/providers.js | 6 ++ 13 files changed, 327 insertions(+), 6 deletions(-) create mode 100644 src/core/runtime/base.js rename src/core/{uni.js => runtime/index.js} (58%) create mode 100644 src/core/runtime/todo.js create mode 100644 src/platforms/mp-alipay/service/api/providers.js create mode 100644 src/platforms/mp-baidu/service/api/providers.js create mode 100644 src/platforms/mp-weixin/service/api/providers.js diff --git a/build/rollup.config.js b/build/rollup.config.js index 83ea8ffb7..a4f660320 100644 --- a/build/rollup.config.js +++ b/build/rollup.config.js @@ -8,7 +8,7 @@ const GLOBAL = { 'mp-baidu': 'swan' } module.exports = { - input: 'src/core/uni.js', + input: 'src/core/runtime/index.js', output: { file: `packages/uni-${process.env.UNI_PLATFORM}/dist/index.js`, format: 'es' diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index 052920cbc..eda5d20f8 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -97,6 +97,67 @@ function upx2px (number, newDeviceWidth) { return number } +const todoApis = Object.create(null); + +const TODOS = [ + 'subscribePush', + 'unsubscribePush', + 'onPush', + 'offPush', + 'share' +]; + +function createTodoApi (name) { + return function todoApi ({ + fail, + complete + }) { + const res = { + errMsg: `${name}:fail:暂不支持 ${name} 方法` + }; + isFn(fail) && fail(res); + isFn(complete) && complete(res); + } +} + +TODOS.forEach(function (name) { + todoApis[name] = createTodoApi(name); +}); + +var providers = { + oauth: ['alipay'], + share: ['alipay'], + payment: ['alipay'], + push: ['alipay'] +}; + +function getProvider ({ + service, + success, + fail, + complete +}) { + let res = false; + if (providers[service]) { + res = { + errMsg: 'getProvider:ok', + service, + provider: providers[service] + }; + isFn(success) && success(res); + } else { + res = { + errMsg: 'getProvider:fail:服务[' + service + ']不存在' + }; + isFn(fail) && fail(res); + } + isFn(complete) && complete(res); +} + +var baseApi = /*#__PURE__*/Object.freeze({ + getProvider: getProvider +}); + var api = /*#__PURE__*/Object.freeze({ @@ -114,6 +175,12 @@ if (typeof Proxy !== 'undefined') { if (api[name]) { return promisify(name, api[name]) } + if (baseApi[name]) { + return promisify(name, baseApi[name]) + } + if (todoApis[name]) { + return promisify(name, todoApis[name]) + } if (!my.hasOwnProperty(name)) { return } @@ -123,6 +190,14 @@ if (typeof Proxy !== 'undefined') { } else { uni$1.upx2px = upx2px; + Object.keys(todoApis).forEach(name => { + uni$1[name] = promisify(name, todoApis[name]); + }); + + Object.keys(baseApi).forEach(name => { + uni$1[name] = promisify(name, todoApis[name]); + }); + Object.keys(api).forEach(name => { uni$1[name] = promisify(name, api[name]); }); diff --git a/packages/uni-mp-alipay/package.json b/packages/uni-mp-alipay/package.json index b883f54c2..d14f45601 100644 --- a/packages/uni-mp-alipay/package.json +++ b/packages/uni-mp-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-alipay", - "version": "0.0.1", + "version": "0.0.2", "description": "uni-app mp-alipay", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index bc80606c3..96d58af03 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -97,6 +97,67 @@ function upx2px (number, newDeviceWidth) { return number } +const todoApis = Object.create(null); + +const TODOS = [ + 'subscribePush', + 'unsubscribePush', + 'onPush', + 'offPush', + 'share' +]; + +function createTodoApi (name) { + return function todoApi ({ + fail, + complete + }) { + const res = { + errMsg: `${name}:fail:暂不支持 ${name} 方法` + }; + isFn(fail) && fail(res); + isFn(complete) && complete(res); + } +} + +TODOS.forEach(function (name) { + todoApis[name] = createTodoApi(name); +}); + +var providers = { + oauth: ['baidu'], + share: ['baidu'], + payment: ['baidu'], + push: ['baidu'] +}; + +function getProvider ({ + service, + success, + fail, + complete +}) { + let res = false; + if (providers[service]) { + res = { + errMsg: 'getProvider:ok', + service, + provider: providers[service] + }; + isFn(success) && success(res); + } else { + res = { + errMsg: 'getProvider:fail:服务[' + service + ']不存在' + }; + isFn(fail) && fail(res); + } + isFn(complete) && complete(res); +} + +var baseApi = /*#__PURE__*/Object.freeze({ + getProvider: getProvider +}); + var api = /*#__PURE__*/Object.freeze({ @@ -114,6 +175,12 @@ if (typeof Proxy !== 'undefined') { if (api[name]) { return promisify(name, api[name]) } + if (baseApi[name]) { + return promisify(name, baseApi[name]) + } + if (todoApis[name]) { + return promisify(name, todoApis[name]) + } if (!swan.hasOwnProperty(name)) { return } @@ -123,6 +190,14 @@ if (typeof Proxy !== 'undefined') { } else { uni$1.upx2px = upx2px; + Object.keys(todoApis).forEach(name => { + uni$1[name] = promisify(name, todoApis[name]); + }); + + Object.keys(baseApi).forEach(name => { + uni$1[name] = promisify(name, todoApis[name]); + }); + Object.keys(api).forEach(name => { uni$1[name] = promisify(name, api[name]); }); diff --git a/packages/uni-mp-baidu/package.json b/packages/uni-mp-baidu/package.json index 958c1b31d..938c0b130 100644 --- a/packages/uni-mp-baidu/package.json +++ b/packages/uni-mp-baidu/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-baidu", - "version": "0.0.1", + "version": "0.0.2", "description": "uni-app mp-baidu", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index f10cfc6f8..47ba28e96 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -97,6 +97,67 @@ function upx2px (number, newDeviceWidth) { return number } +const todoApis = Object.create(null); + +const TODOS = [ + 'subscribePush', + 'unsubscribePush', + 'onPush', + 'offPush', + 'share' +]; + +function createTodoApi (name) { + return function todoApi ({ + fail, + complete + }) { + const res = { + errMsg: `${name}:fail:暂不支持 ${name} 方法` + }; + isFn(fail) && fail(res); + isFn(complete) && complete(res); + } +} + +TODOS.forEach(function (name) { + todoApis[name] = createTodoApi(name); +}); + +var providers = { + oauth: ['weixin'], + share: ['weixin'], + payment: ['wxpay'], + push: ['weixin'] +}; + +function getProvider ({ + service, + success, + fail, + complete +}) { + let res = false; + if (providers[service]) { + res = { + errMsg: 'getProvider:ok', + service, + provider: providers[service] + }; + isFn(success) && success(res); + } else { + res = { + errMsg: 'getProvider:fail:服务[' + service + ']不存在' + }; + isFn(fail) && fail(res); + } + isFn(complete) && complete(res); +} + +var baseApi = /*#__PURE__*/Object.freeze({ + getProvider: getProvider +}); + var api = /*#__PURE__*/Object.freeze({ @@ -114,6 +175,12 @@ if (typeof Proxy !== 'undefined') { if (api[name]) { return promisify(name, api[name]) } + if (baseApi[name]) { + return promisify(name, baseApi[name]) + } + if (todoApis[name]) { + return promisify(name, todoApis[name]) + } if (!wx.hasOwnProperty(name)) { return } @@ -123,6 +190,14 @@ if (typeof Proxy !== 'undefined') { } else { uni$1.upx2px = upx2px; + Object.keys(todoApis).forEach(name => { + uni$1[name] = promisify(name, todoApis[name]); + }); + + Object.keys(baseApi).forEach(name => { + uni$1[name] = promisify(name, todoApis[name]); + }); + Object.keys(api).forEach(name => { uni$1[name] = promisify(name, api[name]); }); diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json index 12686f635..75c85ac9d 100644 --- a/packages/uni-mp-weixin/package.json +++ b/packages/uni-mp-weixin/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-weixin", - "version": "0.0.1", + "version": "0.0.2", "description": "uni-app mp-weixin", "main": "dist/index.js", "scripts": { diff --git a/src/core/runtime/base.js b/src/core/runtime/base.js new file mode 100644 index 000000000..b2f23ac98 --- /dev/null +++ b/src/core/runtime/base.js @@ -0,0 +1,28 @@ +import { + isFn +} from 'uni-shared' + +import providers from 'uni-platform/service/api/providers' + +export function getProvider ({ + service, + success, + fail, + complete +}) { + let res = false + if (providers[service]) { + res = { + errMsg: 'getProvider:ok', + service, + provider: providers[service] + } + isFn(success) && success(res) + } else { + res = { + errMsg: 'getProvider:fail:服务[' + service + ']不存在' + } + isFn(fail) && fail(res) + } + isFn(complete) && complete(res) +} diff --git a/src/core/uni.js b/src/core/runtime/index.js similarity index 58% rename from src/core/uni.js rename to src/core/runtime/index.js index d65acb219..aa0d77d44 100644 --- a/src/core/uni.js +++ b/src/core/runtime/index.js @@ -1,10 +1,14 @@ import { promisify -} from './helpers/promise' +} from '../helpers/promise' import { upx2px -} from './service/api/upx2px' +} from '../service/api/upx2px' + +import todoApi from './todo' + +import * as baseApi from './base' import * as api from 'uni-platform/service/api/index.js' @@ -19,6 +23,12 @@ if (typeof Proxy !== 'undefined') { if (api[name]) { return promisify(name, api[name]) } + if (baseApi[name]) { + return promisify(name, baseApi[name]) + } + if (todoApi[name]) { + return promisify(name, todoApi[name]) + } if (!__GLOBAL__.hasOwnProperty(name)) { return } @@ -28,6 +38,14 @@ if (typeof Proxy !== 'undefined') { } else { uni.upx2px = upx2px + Object.keys(todoApi).forEach(name => { + uni[name] = promisify(name, todoApi[name]) + }) + + Object.keys(baseApi).forEach(name => { + uni[name] = promisify(name, todoApi[name]) + }) + Object.keys(api).forEach(name => { uni[name] = promisify(name, api[name]) }) diff --git a/src/core/runtime/todo.js b/src/core/runtime/todo.js new file mode 100644 index 000000000..1e8d2349b --- /dev/null +++ b/src/core/runtime/todo.js @@ -0,0 +1,32 @@ +import { + isFn +} from 'uni-shared' + +const todoApis = Object.create(null) + +const TODOS = [ + 'subscribePush', + 'unsubscribePush', + 'onPush', + 'offPush', + 'share' +] + +function createTodoApi (name) { + return function todoApi ({ + fail, + complete + }) { + const res = { + errMsg: `${name}:fail:暂不支持 ${name} 方法` + } + isFn(fail) && fail(res) + isFn(complete) && complete(res) + } +} + +TODOS.forEach(function (name) { + todoApis[name] = createTodoApi(name) +}) + +export default todoApis diff --git a/src/platforms/mp-alipay/service/api/providers.js b/src/platforms/mp-alipay/service/api/providers.js new file mode 100644 index 000000000..ed1de98d3 --- /dev/null +++ b/src/platforms/mp-alipay/service/api/providers.js @@ -0,0 +1,6 @@ +export default { + oauth: ['alipay'], + share: ['alipay'], + payment: ['alipay'], + push: ['alipay'] +} diff --git a/src/platforms/mp-baidu/service/api/providers.js b/src/platforms/mp-baidu/service/api/providers.js new file mode 100644 index 000000000..6604d7313 --- /dev/null +++ b/src/platforms/mp-baidu/service/api/providers.js @@ -0,0 +1,6 @@ +export default { + oauth: ['baidu'], + share: ['baidu'], + payment: ['baidu'], + push: ['baidu'] +} diff --git a/src/platforms/mp-weixin/service/api/providers.js b/src/platforms/mp-weixin/service/api/providers.js new file mode 100644 index 000000000..85e70a2cf --- /dev/null +++ b/src/platforms/mp-weixin/service/api/providers.js @@ -0,0 +1,6 @@ +export default { + oauth: ['weixin'], + share: ['weixin'], + payment: ['wxpay'], + push: ['weixin'] +} -- GitLab