From 3f47718b5d08b9da977e92322d1c896e0aaa85d8 Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 21 May 2020 14:27:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=20class=20=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E4=B8=AD=E5=90=AB=E6=9C=89=20rpx=20=E4=B8=8D=E7=94=9F?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98=20question/96981?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/addStylesClient.js | 35 +++++++++---------- .../lib/addStylesClient.js | 4 +-- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/vue-cli-plugin-uni/packages/app-vue-style-loader/lib/addStylesClient.js b/packages/vue-cli-plugin-uni/packages/app-vue-style-loader/lib/addStylesClient.js index 93890947a3..7db1fa5f37 100644 --- a/packages/vue-cli-plugin-uni/packages/app-vue-style-loader/lib/addStylesClient.js +++ b/packages/vue-cli-plugin-uni/packages/app-vue-style-loader/lib/addStylesClient.js @@ -221,29 +221,28 @@ function applyToTag (styleElement, obj) { } } -//fixed by xxxxxx -var UPX_RE = /([+-]?\d+(\.\d+)?)[r|u]px/g -var VAR_STATUS_BAR_HEIGHT = /var\(--status-bar-height\)/gi -var VAR_WINDOW_TOP = /var\(--window-top\)/gi -var VAR_WINDOW_BOTTOM = /var\(--window-bottom\)/gi - -var statusBarHeight = false -function processCss(css) { +//fixed by xxxxxx +var UPX_RE = /([+-]?\d+(\.\d+)?)[r|u]px/g +var VAR_STATUS_BAR_HEIGHT = /var\(--status-bar-height\)/gi +var VAR_WINDOW_TOP = /var\(--window-top\)/gi +var VAR_WINDOW_BOTTOM = /var\(--window-bottom\)/gi + +var statusBarHeight = false +function processCss(css) { if (!uni.canIUse('css.var')) { //不支持 css 变量 if (statusBarHeight === false) { statusBarHeight = plus.navigator.getStatusbarHeight() - } + } var offset = { statusBarHeight: statusBarHeight, top: window.__WINDOW_TOP || 0, bottom: window.__WINDOW_BOTTOM || 0 - } - css = css.replace(VAR_STATUS_BAR_HEIGHT, offset.statusBarHeight + 'px') - .replace(VAR_WINDOW_TOP, offset.top + 'px') - .replace(VAR_WINDOW_BOTTOM, offset.bottom + 'px') - } - return css - .replace(UPX_RE, function(a, b) { - return uni.upx2px(b) + 'px' - }) + } + css = css.replace(VAR_STATUS_BAR_HEIGHT, offset.statusBarHeight + 'px') + .replace(VAR_WINDOW_TOP, offset.top + 'px') + .replace(VAR_WINDOW_BOTTOM, offset.bottom + 'px') + } + return css.replace(/\{.+?\}/gs, css => css.replace(UPX_RE, function (a, b) { + return uni.upx2px(b) + 'px' + })) } diff --git a/packages/vue-cli-plugin-uni/packages/h5-vue-style-loader/lib/addStylesClient.js b/packages/vue-cli-plugin-uni/packages/h5-vue-style-loader/lib/addStylesClient.js index c0bdff387c..94f20dce4f 100644 --- a/packages/vue-cli-plugin-uni/packages/h5-vue-style-loader/lib/addStylesClient.js +++ b/packages/vue-cli-plugin-uni/packages/h5-vue-style-loader/lib/addStylesClient.js @@ -250,9 +250,9 @@ function processCss(css) { .replace(BODY_SCOPED_RE, page) .replace(BODY_RE, '') .replace(PAGE_SCOPED_RE, 'body.' + page + ' uni-page-body') - .replace(UPX_RE, function(a, b) { + .replace(/\{.+?\}/gs, css => css.replace(UPX_RE, function (a, b) { return uni.upx2px(b) + 'px' - }) + })) } function getPage() { -- GitLab