This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

修改框架props设定逻辑,一旦指定类型,就必须正确传值

old
宇天 2018-02-09 13:15:28 +08:00
parent 88dab988da
commit d6328a362c
2 changed files with 70 additions and 52 deletions

View File

@ -181,7 +181,8 @@
return '' return ''
}, },
check: function(val) { check: function(val) {
return Anot.type(val) === this.checkType this.result = Anot.type(val)
return this.result === this.checkType
}, },
call: function() { call: function() {
return this.toString() return this.toString()
@ -3293,7 +3294,8 @@
createSignalTower(elem, newVmodel) createSignalTower(elem, newVmodel)
hideProperty(newVmodel, '$elem', elem) hideProperty(newVmodel, '$elem', elem)
if (vmodels.length) { if (vmodels.length) {
attrs.forEach(function(attr, i) { var props = {}
attrs.forEach(function(attr) {
if (/^:/.test(attr.name)) { if (/^:/.test(attr.name)) {
var name = attr.name.match(rmsAttr)[1] var name = attr.name.match(rmsAttr)[1]
var value = null var value = null
@ -3304,21 +3306,7 @@
value = parseExpr(attr.value, vmodels, {}).apply(0, vmodels) value = parseExpr(attr.value, vmodels, {}).apply(0, vmodels)
value = toJson(value) value = toJson(value)
elem.removeAttribute(attr.name) elem.removeAttribute(attr.name)
if (!value) { props[name] = 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
}
} catch (error) { } catch (error) {
log( log(
'Props parse faild on (%s[class=%s]),', '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) //扫描特性节点 scanAttr(elem, vm) //扫描特性节点

View File

@ -24,6 +24,7 @@ let defconf = {
maskClose: false, //遮罩点击关闭弹窗 maskClose: false, //遮罩点击关闭弹窗
radius: '0px', //弹窗圆角半径 radius: '0px', //弹窗圆角半径
area: ['auto', 'auto'], area: ['auto', 'auto'],
shift: [null, null], // 出现的地方
title: '提示', //弹窗主标题(在工具栏上的) title: '提示', //弹窗主标题(在工具栏上的)
menubar: true, //是否显示菜单栏 menubar: true, //是否显示菜单栏
content: '', // 弹窗的内容 content: '', // 弹窗的内容
@ -94,34 +95,43 @@ const __layer__ = function(conf) {
} }
const _layer = { const _layer = {
alert: function(msg, conf) { alert: function(content, title, cb) {
if (typeof conf === 'function') { let opt = { content, fixed: true, icon: 5 }
conf = { methods: { yes: conf, no: conf } }
} else if (typeof conf === 'object') { if (typeof title === 'function') {
conf = conf opt.yes = title
} else { } else {
conf = {} title += ''
if (title) {
opt.title = title
}
if (cb && typeof cb === 'function') {
opt.yes = cb
}
} }
conf.icon = 5 return _layer.open(opt)
conf.content = msg
conf.fixed = true
return _layer.open(conf)
}, },
confirm: function(msg, yescb, nocb) { confirm: function(content, title, yescb, nocb) {
var conf = {} let opt = { content, fixed: true, icon: 0, type: 2 }
if (typeof yescb === 'function') {
conf = { yes: yescb } if (typeof title === 'function') {
} else if (typeof yescb === 'object') { opt.yes = title
conf = yescb 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 return _layer.open(opt)
conf.icon = 0
conf.content = msg
if (typeof nocb === 'function') {
conf.no = nocb
}
conf.fixed = true
return _layer.open(conf)
}, },
msg: function(msg, conf) { msg: function(msg, conf) {
if (typeof conf !== 'object') { if (typeof conf !== 'object') {
@ -196,7 +206,7 @@ const _layer = {
conf.menubar = false conf.menubar = false
return _layer.open(conf) return _layer.open(conf)
}, },
prompt: function(msg, yescb) { prompt: function(title, yescb) {
if (typeof yescb !== 'function') { if (typeof yescb !== 'function') {
return console.error( return console.error(
'argument [callback] requires a function, but ' + 'argument [callback] requires a function, but ' +
@ -204,16 +214,16 @@ const _layer = {
' given' ' given'
) )
} }
var conf = { let opt = {
type: 3, type: 3,
prompt: '', prompt: '',
title: msg, title,
content: content:
'<input class="prompt-value" data-duplex-focus :class="{alert: !prompt}" :duplex="prompt" />', '<input class="prompt-value" data-duplex-focus :class="{alert: !prompt}" :duplex="prompt" />',
fixed: true, fixed: true,
yes: yescb yes: yescb
} }
return _layer.open(conf) return _layer.open(opt)
}, },
use: function(skin, callback) { use: function(skin, callback) {
require(['css!./skin/' + skin], callback) require(['css!./skin/' + skin], callback)
@ -279,13 +289,16 @@ __layer__.prototype = {
...conf.state ...conf.state
}, },
props: conf.props, props: conf.props,
skip: ['area', 'shift', 'skin', 'mask', 'maskClose'],
methods: { methods: {
onMaskClick: function() { onMaskClick: function() {
if (this.type < 4) { if (this.type < 4 && !this.maskClose) {
this.$refs.layer.classList.add('scale') this.$refs.layer.classList.add('scale')
setTimeout(() => { setTimeout(() => {
this.$refs.layer.classList.remove('scale') this.$refs.layer.classList.remove('scale')
}, 100) }, 100)
} else {
this.close()
} }
}, },
handleConfirm: function() { handleConfirm: function() {
@ -326,9 +339,8 @@ __layer__.prototype = {
} }
//base版没有iframe类型 //base版没有iframe类型
if (this.init.state.type === 4) { if (this.init.state.type === 4) {
this.icon.state.type = 7 this.init.state.type = 7
} }
console.log(this.init)
return this return this
}, },
create: function() { create: function() {
@ -542,10 +554,6 @@ __layer__.prototype = {
Anot(layerDom[_this.init.$id][1]).css(style) Anot(layerDom[_this.init.$id][1]).css(style)
}, 4) }, 4)
// if (this.init.success && typeof this.init.success === 'function') {
// //弹窗成功的回调
// this.init.success(this.init.$id)
// }
// loading类型,回调需要自动触发 // loading类型,回调需要自动触发
if (state.type > 3) { if (state.type > 3) {
//大于0自动触发超时关闭 //大于0自动触发超时关闭