From 8cf72d2c30b8862cdd317c0c98954d8862901678 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 29 Apr 2019 14:39:23 +0800 Subject: [PATCH] build uni runtime(app-plus add subNVue) --- packages/uni-app-plus/dist/index.js | 71 +++++++++++++++++-- packages/uni-app-plus/package.json | 2 +- src/core/helpers/promise.js | 2 +- src/platforms/app-plus/service/api/index.js | 6 +- .../app-plus/service/api/sub-nvue.js | 44 ++++++++++++ 5 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 src/platforms/app-plus/service/api/sub-nvue.js diff --git a/packages/uni-app-plus/dist/index.js b/packages/uni-app-plus/dist/index.js index 75c469213..ed30890e6 100644 --- a/packages/uni-app-plus/dist/index.js +++ b/packages/uni-app-plus/dist/index.js @@ -40,7 +40,7 @@ const camelize = cached((str) => { return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') }); -const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/; +const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/; const CONTEXT_API_RE = /^create|Manager$/; @@ -144,7 +144,9 @@ function upx2px (number, newDeviceWidth) { return number < 0 ? -result : result } -var protocols = {}; +const protocols = {}; +const todos = []; +const canIUses = []; const CALLBACKS = ['success', 'fail', 'cancel', 'complete']; @@ -248,7 +250,52 @@ TODOS.forEach(function (name) { todoApis[name] = createTodoApi(name); }); -function requireNativePlugin (pluginName) { +function wrapper$1 (webview) { + webview.$processed = true; + if (!webview.__uniapp_mask_id) { + return + } + const maskColor = webview.__uniapp_mask; + const maskWebview = plus.webview.getWebviewById(webview.__uniapp_mask_id); + const oldShow = webview.show; + const oldHide = webview.hide; + const oldClose = webview.close; + + const showMask = function () { + maskWebview.setStyle({ + mask: maskColor + }); + }; + const closeMask = function () { + maskWebview.setStyle({ + mask: 'none' + }); + }; + webview.show = function (...args) { + showMask(); + return oldShow.apply(webview, args) + }; + webview.hide = function (...args) { + closeMask(); + return oldHide.apply(webview, args) + }; + webview.close = function (...args) { + closeMask(); + return oldClose.apply(webview, args) + }; +} + +const subNVue = { + getSubNVueById (id) { + const webview = plus.webview.getWebviewById(id); + if (webview && !webview.$processed) { + wrapper$1(webview); + } + return webview + } +}; + +function requireNativePlugin (pluginName) { /* eslint-disable no-undef */ if (typeof weex !== 'undefined') { return weex.requireModule(pluginName) @@ -258,7 +305,8 @@ function requireNativePlugin (pluginName) { } var api = /*#__PURE__*/Object.freeze({ - requireNativePlugin: requireNativePlugin + requireNativePlugin: requireNativePlugin, + subNVue: subNVue }); const MPPage = Page; @@ -532,7 +580,7 @@ function getProperties (props, isBehavior = false, file = '') { return properties } -function wrapper$1 (event) { +function wrapper$2 (event) { // TODO 又得兼容 mpvue 的 mp 对象 try { event.mp = JSON.parse(JSON.stringify(event)); @@ -683,7 +731,7 @@ const ONCE = '~'; const CUSTOM = '^'; function handleEvent (event) { - event = wrapper$1(event); + event = wrapper$2(event); // [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]] const eventOpts = (event.currentTarget || event.target).dataset.eventOpts; @@ -975,6 +1023,17 @@ function createComponent (vueOptions) { return initComponent$1(componentOptions, vueOptions) } +todos.forEach(todoApi => { + protocols[todoApi] = false; +}); + +canIUses.forEach(canIUseApi => { + const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name : canIUseApi; + if (!wx.canIUse(apiName)) { + protocols[canIUseApi] = false; + } +}); + let uni = {}; if (typeof Proxy !== 'undefined') { diff --git a/packages/uni-app-plus/package.json b/packages/uni-app-plus/package.json index 888421080..ed895201f 100644 --- a/packages/uni-app-plus/package.json +++ b/packages/uni-app-plus/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-app-plus", - "version": "0.0.230", + "version": "0.0.231", "description": "uni-app app-plus", "main": "dist/index.js", "scripts": { diff --git a/src/core/helpers/promise.js b/src/core/helpers/promise.js index 613d30f8c..3a9fad8bf 100644 --- a/src/core/helpers/promise.js +++ b/src/core/helpers/promise.js @@ -2,7 +2,7 @@ import { isFn } from 'uni-shared' -const SYNC_API_RE = /requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/ +const SYNC_API_RE = /subNVue|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$/ const CONTEXT_API_RE = /^create|Manager$/ diff --git a/src/platforms/app-plus/service/api/index.js b/src/platforms/app-plus/service/api/index.js index aa0c5d865..0e956fdbc 100644 --- a/src/platforms/app-plus/service/api/index.js +++ b/src/platforms/app-plus/service/api/index.js @@ -1,8 +1,10 @@ -export function requireNativePlugin (pluginName) { +export function requireNativePlugin (pluginName) { /* eslint-disable no-undef */ if (typeof weex !== 'undefined') { return weex.requireModule(pluginName) } /* eslint-disable no-undef */ return __requireNativePlugin__(pluginName) -} +} + +export * from './sub-nvue' diff --git a/src/platforms/app-plus/service/api/sub-nvue.js b/src/platforms/app-plus/service/api/sub-nvue.js new file mode 100644 index 000000000..9e2c626bc --- /dev/null +++ b/src/platforms/app-plus/service/api/sub-nvue.js @@ -0,0 +1,44 @@ +function wrapper (webview) { + webview.$processed = true + if (!webview.__uniapp_mask_id) { + return + } + const maskColor = webview.__uniapp_mask + const maskWebview = plus.webview.getWebviewById(webview.__uniapp_mask_id) + const oldShow = webview.show + const oldHide = webview.hide + const oldClose = webview.close + + const showMask = function () { + maskWebview.setStyle({ + mask: maskColor + }) + } + const closeMask = function () { + maskWebview.setStyle({ + mask: 'none' + }) + } + webview.show = function (...args) { + showMask() + return oldShow.apply(webview, args) + } + webview.hide = function (...args) { + closeMask() + return oldHide.apply(webview, args) + } + webview.close = function (...args) { + closeMask() + return oldClose.apply(webview, args) + } +} + +export const subNVue = { + getSubNVueById (id) { + const webview = plus.webview.getWebviewById(id) + if (webview && !webview.$processed) { + wrapper(webview) + } + return webview + } +} -- GitLab