From 0f20fc7c7815e4f6a0a2e0a1f41c15258e56cd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Tue, 24 Jul 2018 01:45:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A1=86=E6=9E=B6=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E8=A7=A3=E6=9E=90=E6=97=B6=E7=9A=84=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E4=BC=A0=E9=80=92;=E4=BC=98=E5=8C=96=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=E6=8C=89=E9=92=AE=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?;=E4=BC=98=E5=8C=96tree=E7=BB=84=E4=BB=B6=E7=9A=84=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E9=85=8D=E7=BD=AE;=E4=BC=98=E5=8C=96=E8=B7=AF?= =?UTF-8?q?=E7=94=B1link=E5=8F=8A=E8=B7=AF=E7=94=B1=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/anot-touch.js | 4 ++++ src/js/anot-touch.shim.js | 4 ++++ src/js/anot.js | 4 ++++ src/js/anot.shim.js | 4 ++++ src/js/form/index.js | 5 ++++- src/js/router/index.js | 27 ++++++++++++++++++++++++--- src/js/tree/index.js | 1 + 7 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/js/anot-touch.js b/src/js/anot-touch.js index 692abbc..d5a7464 100644 --- a/src/js/anot-touch.js +++ b/src/js/anot-touch.js @@ -3365,6 +3365,10 @@ const _Anot = (function() { var camelizeName = camelize(name) if (camelizeName.indexOf('@') === 0) { camelizeName = camelizeName.slice(1) + attr.value = attr.value.replace(/\(.*\)$/, '') + if (vm.$id.slice(0, 11) === '$proxy$each') { + vm = vm.$up + } if ( vm.hasOwnProperty(attr.value) && typeof vm[attr.value] === 'function' diff --git a/src/js/anot-touch.shim.js b/src/js/anot-touch.shim.js index 3187554..d20cf27 100644 --- a/src/js/anot-touch.shim.js +++ b/src/js/anot-touch.shim.js @@ -3380,6 +3380,10 @@ var camelizeName = camelize(name) if (camelizeName.indexOf('@') === 0) { camelizeName = camelizeName.slice(1) + attr.value = attr.value.replace(/\(.*\)$/, '') + if (vm.$id.slice(0, 11) === '$proxy$each') { + vm = vm.$up + } if ( vm.hasOwnProperty(attr.value) && typeof vm[attr.value] === 'function' diff --git a/src/js/anot.js b/src/js/anot.js index 2926abc..024f44e 100644 --- a/src/js/anot.js +++ b/src/js/anot.js @@ -3365,6 +3365,10 @@ const _Anot = (function() { var camelizeName = camelize(name) if (camelizeName.indexOf('@') === 0) { camelizeName = camelizeName.slice(1) + attr.value = attr.value.replace(/\(.*\)$/, '') + if (vm.$id.slice(0, 11) === '$proxy$each') { + vm = vm.$up + } if ( vm.hasOwnProperty(attr.value) && typeof vm[attr.value] === 'function' diff --git a/src/js/anot.shim.js b/src/js/anot.shim.js index 5b619db..cc4613d 100644 --- a/src/js/anot.shim.js +++ b/src/js/anot.shim.js @@ -3380,6 +3380,10 @@ var camelizeName = camelize(name) if (camelizeName.indexOf('@') === 0) { camelizeName = camelizeName.slice(1) + attr.value = attr.value.replace(/\(.*\)$/, '') + if (vm.$id.slice(0, 11) === '$proxy$each') { + vm = vm.$up + } if ( vm.hasOwnProperty(attr.value) && typeof vm[attr.value] === 'function' diff --git a/src/js/form/index.js b/src/js/form/index.js index 59a2b8a..d0efa65 100644 --- a/src/js/form/index.js +++ b/src/js/form/index.js @@ -57,7 +57,7 @@ Anot.component('button', { return } if (typeof this.props.click === 'function') { - this.props.click() + this.props.click(this.props.prop) } } } @@ -299,6 +299,9 @@ Anot.component('input', { this.active = false }, onKeyup(ev) { + if (this.disabled) { + return + } if (ev.keyCode === 13) { if (typeof this.props.submit === 'function') { this.props.submit() diff --git a/src/js/router/index.js b/src/js/router/index.js index 41b818e..b9106da 100644 --- a/src/js/router/index.js +++ b/src/js/router/index.js @@ -28,6 +28,7 @@ const DEFAULT_OPTIONS = { prefix: /^(#!|#)[\/]?/, //hash前缀正则 allowReload: true //连续点击同一个链接是否重新加载 } +const LINKS = [] const RULE_REGEXP = /(:id)|(\{id\})|(\{id:([A-z\d\,\[\]\{\}\-\+\*\?\!:\^\$]*)\})/g class Router { @@ -170,7 +171,13 @@ class Router { this.last = this.path this.path = path - + LINKS.forEach(vm => { + if (vm.rule.test(this.path)) { + vm.active = true + } else { + vm.active = false + } + }) for (let i = 0, route; (route = this.table[i++]); ) { let args = path.match(route.regexp) if (args) { @@ -220,11 +227,19 @@ class Router { Anot.component('link', { __init__(props, state, next) { + if (!Anot.router) { + return Anot.error('使用前,请先初始化路由') + } let { mode } = Anot.router.options if (!props.to) { return } - + this.setAttribute(':class', '{active: active}') + state.rule = Anot.router.__parseRule__( + props.to.replace(/^[\/]+|[\/]+$|\s+/g, ''), + {} + ).regexp + props.label = props.label || this.textContent if (mode === 'hash') { state.link = '#!' + props.to } else { @@ -236,8 +251,14 @@ Anot.component('link', { render() { return '' }, + skip: ['rule'], + componentDidMount() { + this.active = this.rule.test(Anot.router.path) + LINKS.push(this) + }, state: { - link: '' + link: '', + active: false }, props: { label: '' diff --git a/src/js/tree/index.js b/src/js/tree/index.js index 22ce836..2333810 100644 --- a/src/js/tree/index.js +++ b/src/js/tree/index.js @@ -106,6 +106,7 @@ export default Anot.component('tree', { } }, state: { + expand: false, __LIST_DICT__: {}, list: [], value: null,