From 2e9ef42265fbacc01cf01a2e58511b6d62d4e2ca Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 4 Aug 2020 17:10:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AD=97=E8=8A=82=E8=B7=B3=E5=8A=A8?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=87=AA=E5=AE=9A=E4=B9=89=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=94=AF=E6=8C=81=20v-show=20=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/compiler-mp-toutiao.spec.js | 33 +++++++++++-------- .../__tests__/compiler-mp-weixin.spec.js | 7 ++++ .../__tests__/compiler.spec.js | 4 --- .../lib/template/traverse.js | 12 +++++-- .../lib/plugin/generate-app.js | 5 +-- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js index 38b54dfc2..92a6c8d95 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-toutiao.spec.js @@ -1,10 +1,10 @@ const compiler = require('../lib') function assertCodegen (template, templateCode, renderCode = 'with(this){}', options = {}) { - const res = compiler.compile(template, { + const res = compiler.compile(template, { resourcePath: 'test.wxml', mp: Object.assign({ - minified: true, + minified: true, isTest: true, platform: 'mp-toutiao' }, options) @@ -20,13 +20,13 @@ describe('mp:compiler-mp-toutiao', () => { '', '' ) - }) - - it('generate ref', () => { - assertCodegen( - '', - '' - ) + }) + + it('generate ref', () => { + assertCodegen( + '', + '' + ) }) it('generate class binding', () => { @@ -49,10 +49,10 @@ describe('mp:compiler-mp-toutiao', () => { assertCodegen( '

5

', '5' - ) - assertCodegen( - '
6
', - '6' + ) + assertCodegen( + '
6
', + '6' ) // assertCodegen( // `
6
`, @@ -72,4 +72,11 @@ describe('mp:compiler-mp-toutiao', () => { '9' ) }) + + it('generate v-show directive', () => { + assertCodegen( + 'hello world', + 'hello world' + ) + }) }) diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js index 913a31991..73ac16d5f 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-weixin.spec.js @@ -132,4 +132,11 @@ describe('mp:compiler-mp-weixin', () => { ) assertCodegen('', '') }) + + it('generate v-show directive', () => { + assertCodegen( + 'hello world', + 'hello world' + ) + }) }) diff --git a/packages/uni-template-compiler/__tests__/compiler.spec.js b/packages/uni-template-compiler/__tests__/compiler.spec.js index 1835c1b98..9b999e9a4 100644 --- a/packages/uni-template-compiler/__tests__/compiler.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler.spec.js @@ -277,10 +277,6 @@ describe('mp:compiler', () => { 'hello world', '' ) - assertCodegen( - 'hello world', - 'hello world' - ) }) it('generate DOM props with v-bind directive', () => { diff --git a/packages/uni-template-compiler/lib/template/traverse.js b/packages/uni-template-compiler/lib/template/traverse.js index 3ffd1bc02..7c87d3c77 100644 --- a/packages/uni-template-compiler/lib/template/traverse.js +++ b/packages/uni-template-compiler/lib/template/traverse.js @@ -227,9 +227,17 @@ function traverseDataNode (dataNode, state, node) { objectExpression.properties.find(valueProperty => { const isValue = valueProperty.key.name === 'value' if (isValue) { + let key // 自定义组件不支持 hidden 属性 - const platforms = ['mp-weixin', 'mp-qq'] - ret[platforms.includes(state.options.platform.name) && isComponent(node.type) ? ATTE_DATA_CUSTOM_HIDDEN : 'hidden'] = genCode(valueProperty.value, false, true) + const platform = state.options.platform.name + const platforms = ['mp-weixin', 'mp-qq', 'mp-toutiao'] + if (isComponent(node.type) && platforms.includes(platform)) { + // 字节跳动小程序自定义属性不会反应在DOM上,只能使用事件格式 + key = `${platform === 'mp-toutiao' ? 'bind:-' : ''}${ATTE_DATA_CUSTOM_HIDDEN}` + } else { + key = 'hidden' + } + ret[key] = genCode(valueProperty.value, false, true) } return isValue }) diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-app.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-app.js index e108a526a..d5a5a0897 100644 --- a/packages/webpack-uni-mp-loader/lib/plugin/generate-app.js +++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-app.js @@ -46,8 +46,9 @@ module.exports = function generateApp (compilation) { } // 框架预设样式 用于隐藏自定义组件 - const platforms = ['mp-weixin', 'mp-qq'] - const presetStyle = platforms.includes(process.env.UNI_PLATFORM) ? '[data-custom-hidden="true"]{display: none !important;}' : '' + // TODO 分平台 import 不同 css + const platforms = ['mp-weixin', 'mp-qq', 'mp-toutiao'] + const presetStyle = platforms.includes(process.env.UNI_PLATFORM) ? '[data-custom-hidden="true"],[bind-data-custom-hidden="true"]{display: none !important;}' : '' if (compilation.assets[`common/main${ext}`]) { // 是否存在 main.css importMainCss = `@import './common/main${ext}';` -- GitLab