From 7c47df4ab420647ac5ec89e79a83d3d5968071ef Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 10 Jan 2020 13:28:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=B4=E6=9D=A1=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=20swiper=20=E5=A2=9E=E5=8A=A0=E5=B1=9E=E6=80=A7=20dis?= =?UTF-8?q?able-touch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-template-compiler/lib/index.js | 5 +++- .../lib/module-toutiao.js | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 packages/uni-template-compiler/lib/module-toutiao.js diff --git a/packages/uni-template-compiler/lib/index.js b/packages/uni-template-compiler/lib/index.js index 424594a30..9c4f61d62 100644 --- a/packages/uni-template-compiler/lib/index.js +++ b/packages/uni-template-compiler/lib/index.js @@ -19,6 +19,7 @@ const generateTemplate = require('./template/generate') const compilerModule = require('./module') const compilerAlipayModule = require('./module-alipay') +const compilerToutiaoModule = require('./module-toutiao') const generateCodeFrame = require('./codeframe') @@ -75,6 +76,8 @@ module.exports = { if (options.mp.platform === 'mp-alipay') { options.modules.push(compilerAlipayModule) + } else if (options.mp.platform === 'mp-toutiao') { + options.modules.push(compilerToutiaoModule) } const res = compileTemplate(source, Object.assign(options, { @@ -254,4 +257,4 @@ at ${resourcePath}.vue:1`) ssrCompile, ssrCompileToFunctions, generateCodeFrame -} +} diff --git a/packages/uni-template-compiler/lib/module-toutiao.js b/packages/uni-template-compiler/lib/module-toutiao.js new file mode 100644 index 000000000..b609253d6 --- /dev/null +++ b/packages/uni-template-compiler/lib/module-toutiao.js @@ -0,0 +1,24 @@ +module.exports = { + postTransformNode (el) { + if (el.tag === 'swiper') { + const attrsMap = el.attrsMap + let touchable + if (attrsMap[':disable-touch']) { + touchable = `!(${attrsMap[':disable-touch']})` + } else if ('disable-touch' in attrsMap) { + touchable = 'false' + } + if (touchable) { + const attr = el.attrs.find(attr => attr.name === ':touchable') + if (attr) { + attr.value = touchable + } else { + el.attrs.push({ + name: ':touchable', + value: touchable + }) + } + } + } + } +} -- GitLab