From d6328a362c3501c561bad1e29a8343a7c44b8589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Fri, 9 Feb 2018 13:15:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A1=86=E6=9E=B6props?= =?UTF-8?q?=E8=AE=BE=E5=AE=9A=E9=80=BB=E8=BE=91,=E4=B8=80=E6=97=A6?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E7=B1=BB=E5=9E=8B,=E5=B0=B1=E5=BF=85?= =?UTF-8?q?=E9=A1=BB=E6=AD=A3=E7=A1=AE=E4=BC=A0=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/anot.shim.js | 44 +++++++++++++++---------- src/js/layer/base.js | 78 ++++++++++++++++++++++++-------------------- 2 files changed, 70 insertions(+), 52 deletions(-) diff --git a/src/js/anot.shim.js b/src/js/anot.shim.js index d9cf270..d4d0c72 100644 --- a/src/js/anot.shim.js +++ b/src/js/anot.shim.js @@ -181,7 +181,8 @@ return '' }, check: function(val) { - return Anot.type(val) === this.checkType + this.result = Anot.type(val) + return this.result === this.checkType }, call: function() { return this.toString() @@ -3293,7 +3294,8 @@ createSignalTower(elem, newVmodel) hideProperty(newVmodel, '$elem', elem) if (vmodels.length) { - attrs.forEach(function(attr, i) { + var props = {} + attrs.forEach(function(attr) { if (/^:/.test(attr.name)) { var name = attr.name.match(rmsAttr)[1] var value = null @@ -3304,21 +3306,7 @@ value = parseExpr(attr.value, vmodels, {}).apply(0, vmodels) value = toJson(value) elem.removeAttribute(attr.name) - if (!value) { - return - } - if ( - newVmodel.props[name] && - newVmodel.props[name].type === 'PropsTypes' - ) { - if (newVmodel.props[name].check(value)) { - newVmodel.props[name] = value - } else { - Anot.error('props「' + name + '」类型错误!', TypeError) - } - } else { - newVmodel.props[name] = value - } + props[name] = value } catch (error) { log( 'Props parse faild on (%s[class=%s]),', @@ -3330,6 +3318,28 @@ } } }) + // 一旦设定了 props的类型, 就必须传入正确的值 + for (var k in newVmodel.props) { + if (newVmodel.props[k] && newVmodel.props[k].type === 'PropsTypes') { + if (newVmodel.props[k].check(props[k])) { + newVmodel.props[k] = props[k] + delete props[k] + } else { + Anot.error( + 'props.' + + k + + ' needs [' + + newVmodel.props[k].checkType + + '], but [' + + newVmodel.props[k].result + + '] given.', + TypeError + ) + } + } + } + Object.assign(newVmodel.props, props) + props = undefined } } scanAttr(elem, vm) //扫描特性节点 diff --git a/src/js/layer/base.js b/src/js/layer/base.js index 29cc150..7b0dac5 100644 --- a/src/js/layer/base.js +++ b/src/js/layer/base.js @@ -24,6 +24,7 @@ let defconf = { maskClose: false, //遮罩点击关闭弹窗 radius: '0px', //弹窗圆角半径 area: ['auto', 'auto'], + shift: [null, null], // 出现的地方 title: '提示', //弹窗主标题(在工具栏上的) menubar: true, //是否显示菜单栏 content: '', // 弹窗的内容 @@ -94,34 +95,43 @@ const __layer__ = function(conf) { } const _layer = { - alert: function(msg, conf) { - if (typeof conf === 'function') { - conf = { methods: { yes: conf, no: conf } } - } else if (typeof conf === 'object') { - conf = conf + alert: function(content, title, cb) { + let opt = { content, fixed: true, icon: 5 } + + if (typeof title === 'function') { + opt.yes = title } else { - conf = {} + title += '' + if (title) { + opt.title = title + } + if (cb && typeof cb === 'function') { + opt.yes = cb + } } - conf.icon = 5 - conf.content = msg - conf.fixed = true - return _layer.open(conf) + return _layer.open(opt) }, - confirm: function(msg, yescb, nocb) { - var conf = {} - if (typeof yescb === 'function') { - conf = { yes: yescb } - } else if (typeof yescb === 'object') { - conf = yescb + confirm: function(content, title, yescb, nocb) { + let opt = { content, fixed: true, icon: 0, type: 2 } + + if (typeof title === 'function') { + opt.yes = title + if (typeof yescb === 'function') { + opt.no = yescb + } + } else { + title += '' + if (title) { + opt.title = title + } + if (yescb && typeof yescb === 'function') { + opt.yes = yescb + } + if (nocb && typeof nocb === 'function') { + opt.no = nocb + } } - conf.type = 2 - conf.icon = 0 - conf.content = msg - if (typeof nocb === 'function') { - conf.no = nocb - } - conf.fixed = true - return _layer.open(conf) + return _layer.open(opt) }, msg: function(msg, conf) { if (typeof conf !== 'object') { @@ -196,7 +206,7 @@ const _layer = { conf.menubar = false return _layer.open(conf) }, - prompt: function(msg, yescb) { + prompt: function(title, yescb) { if (typeof yescb !== 'function') { return console.error( 'argument [callback] requires a function, but ' + @@ -204,16 +214,16 @@ const _layer = { ' given' ) } - var conf = { + let opt = { type: 3, prompt: '', - title: msg, + title, content: '', fixed: true, yes: yescb } - return _layer.open(conf) + return _layer.open(opt) }, use: function(skin, callback) { require(['css!./skin/' + skin], callback) @@ -279,13 +289,16 @@ __layer__.prototype = { ...conf.state }, props: conf.props, + skip: ['area', 'shift', 'skin', 'mask', 'maskClose'], methods: { onMaskClick: function() { - if (this.type < 4) { + if (this.type < 4 && !this.maskClose) { this.$refs.layer.classList.add('scale') setTimeout(() => { this.$refs.layer.classList.remove('scale') }, 100) + } else { + this.close() } }, handleConfirm: function() { @@ -326,9 +339,8 @@ __layer__.prototype = { } //base版没有iframe类型 if (this.init.state.type === 4) { - this.icon.state.type = 7 + this.init.state.type = 7 } - console.log(this.init) return this }, create: function() { @@ -542,10 +554,6 @@ __layer__.prototype = { Anot(layerDom[_this.init.$id][1]).css(style) }, 4) - // if (this.init.success && typeof this.init.success === 'function') { - // //弹窗成功的回调 - // this.init.success(this.init.$id) - // } // loading类型,回调需要自动触发 if (state.type > 3) { //大于0自动触发超时关闭