From cd29cdb5f541ecaecfc3f0ac97f654b4d02469bf Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 31 Dec 2019 15:59:51 +0800 Subject: [PATCH] feat(v3): add debugRefresh --- packages/uni-app-plus/dist/index.v3.js | 46 ++++++++++++++----- .../dist/parseCustomBlocks.js | 18 ++++++-- .../app-plus/service/api/route/navigate-to.js | 25 +++++----- .../app-plus/service/api/route/re-launch.js | 3 ++ .../app-plus/service/api/route/redirect-to.js | 3 ++ .../app-plus/service/api/route/switch-tab.js | 5 +- .../app-plus/service/framework/page.js | 5 +- .../service/framework/webview/index.js | 13 +++++- 8 files changed, 89 insertions(+), 29 deletions(-) diff --git a/packages/uni-app-plus/dist/index.v3.js b/packages/uni-app-plus/dist/index.v3.js index 54355c832..cbb9bfea2 100644 --- a/packages/uni-app-plus/dist/index.v3.js +++ b/packages/uni-app-plus/dist/index.v3.js @@ -7681,7 +7681,7 @@ var serviceContext = (function () { return webview } - function initWebview (webview, routeOptions) { + function initWebview (webview, routeOptions, url = '') { // 首页或非 nvue 页面 if (webview.id === '1' || !routeOptions.meta.isNVue) { const webviewStyle = parseWebviewStyle( @@ -7689,6 +7689,17 @@ var serviceContext = (function () { '', routeOptions ); + if (url) { + const part = url.split('?'); + webviewStyle.debugRefresh = { + isTab: routeOptions.meta.isTabBar, + arguments: JSON.stringify({ + path: part[0].substr(1), + query: part[1] || '' + }) + }; + } + if (process.env.NODE_ENV !== 'production') { console.log(`[uni-app] updateWebview`, webviewStyle); } @@ -7881,7 +7892,8 @@ var serviceContext = (function () { /** * 首页需要主动registerPage,二级页面路由跳转时registerPage */ - function registerPage ({ + function registerPage ({ + url, path, query, openType, @@ -7920,7 +7932,7 @@ var serviceContext = (function () { console.log(`[uni-app] registerPage`, path, webview.id); } - initWebview(webview, routeOptions); + initWebview(webview, routeOptions, url); const route = path.slice(1); @@ -7986,6 +7998,7 @@ var serviceContext = (function () { } function _navigateTo ({ + url, path, query, animationType, @@ -7998,6 +8011,7 @@ var serviceContext = (function () { showWebview( registerPage({ + url, path, query, openType: 'navigate' @@ -8020,18 +8034,19 @@ var serviceContext = (function () { animationDuration }, callbackId) { const urls = url.split('?'); - const path = urls[0]; - const routeStyles = __uniRoutes.find(route => route.path === path).window; - const globalStyle = __uniConfig.window; - if (!animationType) { - animationType = routeStyles.animationType || globalStyle.animationType || ANI_SHOW; - } - if (!animationDuration) { - animationDuration = routeStyles.animationDuration || globalStyle.animationDuration || ANI_DURATION; + const path = urls[0]; + const routeStyles = __uniRoutes.find(route => route.path === path).window; + const globalStyle = __uniConfig.window; + if (!animationType) { + animationType = routeStyles.animationType || globalStyle.animationType || ANI_SHOW; + } + if (!animationDuration) { + animationDuration = routeStyles.animationDuration || globalStyle.animationDuration || ANI_DURATION; } const query = parseQuery(urls[1] || ''); navigate(path, function () { _navigateTo({ + url, path, query, animationType, @@ -8041,6 +8056,7 @@ var serviceContext = (function () { } function _reLaunch ({ + url, path, query }, callbackId) { @@ -8054,6 +8070,7 @@ var serviceContext = (function () { showWebview( registerPage({ + url, path, query, openType: 'reLaunch' @@ -8082,6 +8099,7 @@ var serviceContext = (function () { const query = parseQuery(urls[1] || ''); navigate(path, function () { _reLaunch({ + url, path, query }, callbackId); @@ -8089,6 +8107,7 @@ var serviceContext = (function () { } function _redirectTo ({ + url, path, query }, callbackId) { @@ -8099,6 +8118,7 @@ var serviceContext = (function () { showWebview( registerPage({ + url, path, query, openType: 'redirect' @@ -8123,6 +8143,7 @@ var serviceContext = (function () { const query = parseQuery(urls[1] || ''); navigate(path, function () { _redirectTo({ + url, path, query }, callbackId); @@ -8130,6 +8151,7 @@ var serviceContext = (function () { } function _switchTab ({ + url, path, from }, callbackId) { @@ -8180,6 +8202,7 @@ var serviceContext = (function () { tabBarPage.$getAppWebview().show('none'); } else { return showWebview(registerPage({ + url, path, query: {}, openType: 'switchTab' @@ -8205,6 +8228,7 @@ var serviceContext = (function () { const path = url.split('?')[0]; navigate(path, function () { _switchTab({ + url, path, from }, callbackId); diff --git a/packages/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/dist/parseCustomBlocks.js b/packages/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/dist/parseCustomBlocks.js index ffea1534d..a474d024a 100644 --- a/packages/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/dist/parseCustomBlocks.js +++ b/packages/vue-cli-plugin-uni/packages/@vue/component-compiler-utils/dist/parseCustomBlocks.js @@ -1,10 +1,22 @@ const { getPlatformFilterTag, - normalizeNodeModules + normalizeNodeModules, + jsPreprocessOptions } = require('@dcloudio/uni-cli-shared/lib/platform') +const preprocessor = require('@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/preprocess') + const FILTER_TAG = getPlatformFilterTag() +function preprocessBlock(block) { + if (block.content) { + block.content = preprocessor.preprocess(block.content, jsPreprocessOptions.context, { + type: jsPreprocessOptions.type + }).trim() + } + return block +} + module.exports = function parseCustomBlocks(descriptor, options) { if (!descriptor.template || !FILTER_TAG || options.isAppNVue) { @@ -23,7 +35,7 @@ module.exports = function parseCustomBlocks(descriptor, options) { block.attrs.lang === FILTER_TAG ) ) { - modules[block.attrs.module] = block + modules[block.attrs.module] = preprocessBlock(block) return true } if ( // renderjs @@ -33,7 +45,7 @@ module.exports = function parseCustomBlocks(descriptor, options) { block.attrs.lang === 'renderjs' ) ) { - descriptor.renderjs = block + descriptor.renderjs = preprocessBlock(block) modules[block.attrs.module] = Object.assign({}, block, { content: '' }) diff --git a/src/platforms/app-plus/service/api/route/navigate-to.js b/src/platforms/app-plus/service/api/route/navigate-to.js index d7523f44b..1ff60f4dc 100644 --- a/src/platforms/app-plus/service/api/route/navigate-to.js +++ b/src/platforms/app-plus/service/api/route/navigate-to.js @@ -1,7 +1,7 @@ import { parseQuery -} from 'uni-shared' - +} from 'uni-shared' + import { ANI_SHOW, ANI_DURATION @@ -25,6 +25,7 @@ import { } from '../../framework/navigator' function _navigateTo ({ + url, path, query, animationType, @@ -37,6 +38,7 @@ function _navigateTo ({ showWebview( registerPage({ + url, path, query, openType: 'navigate' @@ -59,22 +61,23 @@ export function navigateTo ({ animationDuration }, callbackId) { const urls = url.split('?') - const path = urls[0] - const routeStyles = __uniRoutes.find(route => route.path === path).window - const globalStyle = __uniConfig.window - if (!animationType) { - animationType = routeStyles.animationType || globalStyle.animationType || ANI_SHOW - } - if (!animationDuration) { - animationDuration = routeStyles.animationDuration || globalStyle.animationDuration || ANI_DURATION + const path = urls[0] + const routeStyles = __uniRoutes.find(route => route.path === path).window + const globalStyle = __uniConfig.window + if (!animationType) { + animationType = routeStyles.animationType || globalStyle.animationType || ANI_SHOW + } + if (!animationDuration) { + animationDuration = routeStyles.animationDuration || globalStyle.animationDuration || ANI_DURATION } const query = parseQuery(urls[1] || '') navigate(path, function () { _navigateTo({ + url, path, query, animationType, animationDuration }, callbackId) }, openType === 'appLaunch') -} +} diff --git a/src/platforms/app-plus/service/api/route/re-launch.js b/src/platforms/app-plus/service/api/route/re-launch.js index 272d93408..7793375fb 100644 --- a/src/platforms/app-plus/service/api/route/re-launch.js +++ b/src/platforms/app-plus/service/api/route/re-launch.js @@ -22,6 +22,7 @@ import { } from '../../framework/navigator' function _reLaunch ({ + url, path, query }, callbackId) { @@ -35,6 +36,7 @@ function _reLaunch ({ showWebview( registerPage({ + url, path, query, openType: 'reLaunch' @@ -63,6 +65,7 @@ export function reLaunch ({ const query = parseQuery(urls[1] || '') navigate(path, function () { _reLaunch({ + url, path, query }, callbackId) diff --git a/src/platforms/app-plus/service/api/route/redirect-to.js b/src/platforms/app-plus/service/api/route/redirect-to.js index 850c8a555..ade666e23 100644 --- a/src/platforms/app-plus/service/api/route/redirect-to.js +++ b/src/platforms/app-plus/service/api/route/redirect-to.js @@ -20,6 +20,7 @@ import { } from '../../framework/navigator' function _redirectTo ({ + url, path, query }, callbackId) { @@ -30,6 +31,7 @@ function _redirectTo ({ showWebview( registerPage({ + url, path, query, openType: 'redirect' @@ -54,6 +56,7 @@ export function redirectTo ({ const query = parseQuery(urls[1] || '') navigate(path, function () { _redirectTo({ + url, path, query }, callbackId) diff --git a/src/platforms/app-plus/service/api/route/switch-tab.js b/src/platforms/app-plus/service/api/route/switch-tab.js index bc23f9006..9bcea79f5 100644 --- a/src/platforms/app-plus/service/api/route/switch-tab.js +++ b/src/platforms/app-plus/service/api/route/switch-tab.js @@ -23,6 +23,7 @@ import { import tabBar from '../../framework/tab-bar' function _switchTab ({ + url, path, from }, callbackId) { @@ -73,6 +74,7 @@ function _switchTab ({ tabBarPage.$getAppWebview().show('none') } else { return showWebview(registerPage({ + url, path, query: {}, openType: 'switchTab' @@ -98,8 +100,9 @@ export function switchTab ({ const path = url.split('?')[0] navigate(path, function () { _switchTab({ + url, path, from }, callbackId) }, openType === 'appLaunch') -} +} diff --git a/src/platforms/app-plus/service/framework/page.js b/src/platforms/app-plus/service/framework/page.js index f1fbe5a33..843d62432 100644 --- a/src/platforms/app-plus/service/framework/page.js +++ b/src/platforms/app-plus/service/framework/page.js @@ -24,7 +24,8 @@ export function getCurrentPages (returnAll) { /** * 首页需要主动registerPage,二级页面路由跳转时registerPage */ -export function registerPage ({ +export function registerPage ({ + url, path, query, openType, @@ -63,7 +64,7 @@ export function registerPage ({ console.log(`[uni-app] registerPage`, path, webview.id) } - initWebview(webview, routeOptions) + initWebview(webview, routeOptions, url) const route = path.slice(1) diff --git a/src/platforms/app-plus/service/framework/webview/index.js b/src/platforms/app-plus/service/framework/webview/index.js index d95356fde..11cb19168 100644 --- a/src/platforms/app-plus/service/framework/webview/index.js +++ b/src/platforms/app-plus/service/framework/webview/index.js @@ -63,7 +63,7 @@ export function createWebview (path, routeOptions) { return webview } -export function initWebview (webview, routeOptions) { +export function initWebview (webview, routeOptions, url = '') { // 首页或非 nvue 页面 if (webview.id === '1' || !routeOptions.meta.isNVue) { const webviewStyle = parseWebviewStyle( @@ -71,6 +71,17 @@ export function initWebview (webview, routeOptions) { '', routeOptions ) + if (url) { + const part = url.split('?') + webviewStyle.debugRefresh = { + isTab: routeOptions.meta.isTabBar, + arguments: JSON.stringify({ + path: part[0].substr(1), + query: part[1] || '' + }) + } + } + if (process.env.NODE_ENV !== 'production') { console.log(`[uni-app] updateWebview`, webviewStyle) } -- GitLab