编译的时候增加全局事件拦截

编译的时候增加全局事件拦截
This commit is contained in:
穷屌丝 2019-10-10 11:56:45 +08:00 committed by GitHub
parent 071089928c
commit 97375e7452
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -2,6 +2,8 @@ let htmlToJson = require('html2json').html2json
let map = require('./tag-mapping')
let reURL = /^(https?):\/\/.+$/;
const inputEvent = ['bindfocus', 'bindkeydown', 'bindkeypree', 'bindkeyup', 'bindinput', 'bindchange', 'bindblue']
function parse(wxml, fnName) {
return walk(htmlToJson(minifier(wxml)), fnName)
}
@ -28,6 +30,13 @@ function checkIsArray(json) {
tagAttr.bindclick = tagAttr.bindtap;
}
if(tagName === 'input'){
inputEvent.forEach((item) => {
if(tagAttr[item]){
tagAttr[item] = `helpInputEvent.bind(this,this.${tagAttr[item]})`
}
})
}
if (tagName === 'block') {
if(tagAttr){
tagAttr.style = '{{{"width": "100%"}}}';
@ -48,7 +57,6 @@ function checkIsArray(json) {
return false
}
function walk(node, fnName) {
if(checkIsArray(node)){
return `function ${fnName}() {