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

移除template组件标签,统一使用<anot-xx>自定义标签来声明

old
宇天 2018-06-14 19:57:49 +08:00
parent 5ecec460cb
commit 6ad4c35194
12 changed files with 159 additions and 279 deletions

View File

@ -3367,6 +3367,7 @@ const _Anot = (function() {
(attr.specified && !rnoCollect.test(name)) || (attr.specified && !rnoCollect.test(name)) ||
specifiedVars.includes(name) specifiedVars.includes(name)
) { ) {
elem.removeAttribute(name)
if (name.indexOf(ronattr) === 0) { if (name.indexOf(ronattr) === 0) {
name = attr.value.slice(6) name = attr.value.slice(6)
ret[name] = elem[attr.value] ret[name] = elem[attr.value]
@ -3386,7 +3387,6 @@ const _Anot = (function() {
} else { } else {
ret[camelizeName] = parseData(attr.value) ret[camelizeName] = parseData(attr.value)
} }
elem.removeAttribute(name)
} }
} }
} }
@ -3902,18 +3902,10 @@ const _Anot = (function() {
globalHooks.componentWillMount.call(null, vmodel) globalHooks.componentWillMount.call(null, vmodel)
var slots = null var slots = null
var isTemplate = true
if (elem.content) {
if (elem.content.firstElementChild) {
slots = parseSlot(elem.content.children)
}
} else {
isTemplate = false
if (elem.firstElementChild) { if (elem.firstElementChild) {
slots = parseSlot(elem.children) slots = parseSlot(elem.children)
} }
}
Anot.clearHTML(elem) Anot.clearHTML(elem)
var html = render.call(vmodel, slots) || '' var html = render.call(vmodel, slots) || ''
@ -3924,27 +3916,6 @@ const _Anot = (function() {
elem.innerHTML = html elem.innerHTML = html
if (isTemplate) {
// 组件所使用的标签是template,所以必须要要用子元素替换掉
var child = elem.content.firstElementChild
var nullComponent = DOC.createComment('empty component')
elem.parentNode.replaceChild(child || nullComponent, elem)
// 空组件直接跳出
if (!child) {
return
}
child.msResolved = 1
var cssText = elem.style.cssText
var className = elem.className
elem = host.element = child
elem.style && (elem.style.cssText += ';' + cssText)
if (className) {
Anot(elem).addClass(className)
}
}
hideProperty(vmodel, '$elem', elem) hideProperty(vmodel, '$elem', elem)
Anot.fireDom(elem, 'datasetchanged', { Anot.fireDom(elem, 'datasetchanged', {
@ -4013,9 +3984,6 @@ const _Anot = (function() {
function isWidget(el) { function isWidget(el) {
//如果是组件,则返回组件的名字 //如果是组件,则返回组件的名字
var name = el.nodeName.toLowerCase() var name = el.nodeName.toLowerCase()
if (name === 'template' && el.getAttribute('name')) {
return el.getAttribute('name')
}
if (/^anot-([a-z][a-z0-9\-]*)$/.test(name)) { if (/^anot-([a-z][a-z0-9\-]*)$/.test(name)) {
return RegExp.$1 return RegExp.$1
} }

View File

@ -3382,6 +3382,7 @@
(attr.specified && !rnoCollect.test(name)) || (attr.specified && !rnoCollect.test(name)) ||
specifiedVars.includes(name) specifiedVars.includes(name)
) { ) {
elem.removeAttribute(name)
if (name.indexOf(ronattr) === 0) { if (name.indexOf(ronattr) === 0) {
name = attr.value.slice(6) name = attr.value.slice(6)
ret[name] = elem[attr.value] ret[name] = elem[attr.value]
@ -3401,7 +3402,6 @@
} else { } else {
ret[camelizeName] = parseData(attr.value) ret[camelizeName] = parseData(attr.value)
} }
elem.removeAttribute(name)
} }
} }
} }
@ -3917,18 +3917,10 @@
globalHooks.componentWillMount.call(null, vmodel) globalHooks.componentWillMount.call(null, vmodel)
var slots = null var slots = null
var isTemplate = true
if (elem.content) {
if (elem.content.firstElementChild) {
slots = parseSlot(elem.content.children)
}
} else {
isTemplate = false
if (elem.firstElementChild) { if (elem.firstElementChild) {
slots = parseSlot(elem.children) slots = parseSlot(elem.children)
} }
}
Anot.clearHTML(elem) Anot.clearHTML(elem)
var html = render.call(vmodel, slots) || '' var html = render.call(vmodel, slots) || ''
@ -3939,27 +3931,6 @@
elem.innerHTML = html elem.innerHTML = html
if (isTemplate) {
// 组件所使用的标签是template,所以必须要要用子元素替换掉
var child = elem.content.firstElementChild
var nullComponent = DOC.createComment('empty component')
elem.parentNode.replaceChild(child || nullComponent, elem)
// 空组件直接跳出
if (!child) {
return
}
child.msResolved = 1
var cssText = elem.style.cssText
var className = elem.className
elem = host.element = child
elem.style && (elem.style.cssText += ';' + cssText)
if (className) {
Anot(elem).addClass(className)
}
}
hideProperty(vmodel, '$elem', elem) hideProperty(vmodel, '$elem', elem)
Anot.fireDom(elem, 'datasetchanged', { Anot.fireDom(elem, 'datasetchanged', {
@ -4028,9 +3999,6 @@
function isWidget(el) { function isWidget(el) {
//如果是组件,则返回组件的名字 //如果是组件,则返回组件的名字
var name = el.nodeName.toLowerCase() var name = el.nodeName.toLowerCase()
if (name === 'template' && el.getAttribute('name')) {
return el.getAttribute('name')
}
if (/^anot-([a-z][a-z0-9\-]*)$/.test(name)) { if (/^anot-([a-z][a-z0-9\-]*)$/.test(name)) {
return RegExp.$1 return RegExp.$1
} }

View File

@ -3367,6 +3367,7 @@ const _Anot = (function() {
(attr.specified && !rnoCollect.test(name)) || (attr.specified && !rnoCollect.test(name)) ||
specifiedVars.includes(name) specifiedVars.includes(name)
) { ) {
elem.removeAttribute(name)
if (name.indexOf(ronattr) === 0) { if (name.indexOf(ronattr) === 0) {
name = attr.value.slice(6) name = attr.value.slice(6)
ret[name] = elem[attr.value] ret[name] = elem[attr.value]
@ -3386,7 +3387,6 @@ const _Anot = (function() {
} else { } else {
ret[camelizeName] = parseData(attr.value) ret[camelizeName] = parseData(attr.value)
} }
elem.removeAttribute(name)
} }
} }
} }
@ -3902,18 +3902,10 @@ const _Anot = (function() {
globalHooks.componentWillMount.call(null, vmodel) globalHooks.componentWillMount.call(null, vmodel)
var slots = null var slots = null
var isTemplate = true
if (elem.content) {
if (elem.content.firstElementChild) {
slots = parseSlot(elem.content.children)
}
} else {
isTemplate = false
if (elem.firstElementChild) { if (elem.firstElementChild) {
slots = parseSlot(elem.children) slots = parseSlot(elem.children)
} }
}
Anot.clearHTML(elem) Anot.clearHTML(elem)
var html = render.call(vmodel, slots) || '' var html = render.call(vmodel, slots) || ''
@ -3924,27 +3916,6 @@ const _Anot = (function() {
elem.innerHTML = html elem.innerHTML = html
if (isTemplate) {
// 组件所使用的标签是template,所以必须要要用子元素替换掉
var child = elem.content.firstElementChild
var nullComponent = DOC.createComment('empty component')
elem.parentNode.replaceChild(child || nullComponent, elem)
// 空组件直接跳出
if (!child) {
return
}
child.msResolved = 1
var cssText = elem.style.cssText
var className = elem.className
elem = host.element = child
elem.style && (elem.style.cssText += ';' + cssText)
if (className) {
Anot(elem).addClass(className)
}
}
hideProperty(vmodel, '$elem', elem) hideProperty(vmodel, '$elem', elem)
Anot.fireDom(elem, 'datasetchanged', { Anot.fireDom(elem, 'datasetchanged', {
@ -4013,9 +3984,6 @@ const _Anot = (function() {
function isWidget(el) { function isWidget(el) {
//如果是组件,则返回组件的名字 //如果是组件,则返回组件的名字
var name = el.nodeName.toLowerCase() var name = el.nodeName.toLowerCase()
if (name === 'template' && el.getAttribute('name')) {
return el.getAttribute('name')
}
if (/^anot-([a-z][a-z0-9\-]*)$/.test(name)) { if (/^anot-([a-z][a-z0-9\-]*)$/.test(name)) {
return RegExp.$1 return RegExp.$1
} }

View File

@ -3382,6 +3382,7 @@
(attr.specified && !rnoCollect.test(name)) || (attr.specified && !rnoCollect.test(name)) ||
specifiedVars.includes(name) specifiedVars.includes(name)
) { ) {
elem.removeAttribute(name)
if (name.indexOf(ronattr) === 0) { if (name.indexOf(ronattr) === 0) {
name = attr.value.slice(6) name = attr.value.slice(6)
ret[name] = elem[attr.value] ret[name] = elem[attr.value]
@ -3401,7 +3402,6 @@
} else { } else {
ret[camelizeName] = parseData(attr.value) ret[camelizeName] = parseData(attr.value)
} }
elem.removeAttribute(name)
} }
} }
} }
@ -3917,18 +3917,10 @@
globalHooks.componentWillMount.call(null, vmodel) globalHooks.componentWillMount.call(null, vmodel)
var slots = null var slots = null
var isTemplate = true
if (elem.content) {
if (elem.content.firstElementChild) {
slots = parseSlot(elem.content.children)
}
} else {
isTemplate = false
if (elem.firstElementChild) { if (elem.firstElementChild) {
slots = parseSlot(elem.children) slots = parseSlot(elem.children)
} }
}
Anot.clearHTML(elem) Anot.clearHTML(elem)
var html = render.call(vmodel, slots) || '' var html = render.call(vmodel, slots) || ''
@ -3939,27 +3931,6 @@
elem.innerHTML = html elem.innerHTML = html
if (isTemplate) {
// 组件所使用的标签是template,所以必须要要用子元素替换掉
var child = elem.content.firstElementChild
var nullComponent = DOC.createComment('empty component')
elem.parentNode.replaceChild(child || nullComponent, elem)
// 空组件直接跳出
if (!child) {
return
}
child.msResolved = 1
var cssText = elem.style.cssText
var className = elem.className
elem = host.element = child
elem.style && (elem.style.cssText += ';' + cssText)
if (className) {
Anot(elem).addClass(className)
}
}
hideProperty(vmodel, '$elem', elem) hideProperty(vmodel, '$elem', elem)
Anot.fireDom(elem, 'datasetchanged', { Anot.fireDom(elem, 'datasetchanged', {
@ -4028,9 +3999,6 @@
function isWidget(el) { function isWidget(el) {
//如果是组件,则返回组件的名字 //如果是组件,则返回组件的名字
var name = el.nodeName.toLowerCase() var name = el.nodeName.toLowerCase()
if (name === 'template' && el.getAttribute('name')) {
return el.getAttribute('name')
}
if (/^anot-([a-z][a-z0-9\-]*)$/.test(name)) { if (/^anot-([a-z][a-z0-9\-]*)$/.test(name)) {
return RegExp.$1 return RegExp.$1
} }

View File

@ -123,12 +123,7 @@ Anot.ui.datepicker = '1.0.0'
export default Anot.component('datepicker', { export default Anot.component('datepicker', {
render: function() { render: function() {
return `<div return `
class="do-datepicker do-fn-noselect"
:class="{{props.size}}"
:css="{width: props.width, height: props.height, 'line-height': props.height + 'px'}"
:click="cancelBubble">
<label class="date-input"> <label class="date-input">
<input <input
class="input" class="input"
@ -191,10 +186,17 @@ export default Anot.component('datepicker', {
<a :click="onConfirm" class="ok">确定</a> <a :click="onConfirm" class="ok">确定</a>
</dt> </dt>
<dd class="tips" :if="tips" :text="tips"></dd> <dd class="tips" :if="tips" :text="tips"></dd>
</dl> </dl>`
</div>`
}, },
__init__: function(props, state, next) { __init__: function(props, state, next) {
this.classList.add('do-datepicker')
this.classList.add('do-fn-noselect')
this.classList.add(props.size || 'mini')
this.setAttribute(
':css',
"{width: props.width, height: props.height, 'line-height': props.height + 'px'}"
)
this.setAttribute(':click', 'cancelBubble')
// 日期格式化, 不显示时间时, 默认会调用过滤器的格式'Y-m-d H:i:s' // 日期格式化, 不显示时间时, 默认会调用过滤器的格式'Y-m-d H:i:s'
if (!props.showTime && !props.format) { if (!props.showTime && !props.format) {
props.format = 'Y-m-d' props.format = 'Y-m-d'

View File

@ -7,7 +7,7 @@
*/ */
@import "var.scss"; @import "var.scss";
.do-datepicker { position:relative;width:100%; height:100%;color:nth($cgr, 1);font-size:14px; .do-datepicker { position:relative;display:inline-block;width:100%; height:100%;color:nth($cgr, 1);font-size:14px;
&.mini {width:155px;height:30px;line-height:30px;} &.mini {width:155px;height:30px;line-height:30px;}
&.medium {width:175px;height:35px;line-height:35px;} &.medium {width:175px;height:35px;line-height:35px;}

View File

@ -264,10 +264,20 @@ class MEObject {
Anot.component('meditor', { Anot.component('meditor', {
__init__: function(props, state, next) { __init__: function(props, state, next) {
this.classList.add('do-meditor')
this.classList.add('do-meditor__font')
this.setAttribute(':visible', 'editorVisible')
this.setAttribute(':css', '{height: height}')
this.setAttribute(':class', '{fullscreen: fullscreen, preview: preview}')
if (props.hasOwnProperty('$show')) { if (props.hasOwnProperty('$show')) {
state.editorVisible = props.$show state.editorVisible = props.$show
delete props.$show delete props.$show
} }
if (props.height && props.height > 180) {
state.height = props.height
delete props.height
}
next() next()
}, },
render: function() { render: function() {
@ -276,10 +286,6 @@ Anot.component('meditor', {
delete this.toolbar delete this.toolbar
return ` return `
<div
class="do-meditor do-meditor__font"
:visible="editorVisible"
:class="{fullscreen: fullscreen, preview: preview}">
<div class="tool-bar do-fn-noselect">${toolbar}</div> <div class="tool-bar do-fn-noselect">${toolbar}</div>
<textarea <textarea
ref="editor" ref="editor"
@ -292,7 +298,6 @@ Anot.component('meditor', {
class="md-preview do-marked-theme" class="md-preview do-marked-theme"
:visible="preview" :visible="preview"
:html="htmlTxt"></content> :html="htmlTxt"></content>
</div>
` `
}, },
componentDidMount: function(vm, elem) { componentDidMount: function(vm, elem) {
@ -360,6 +365,7 @@ Anot.component('meditor', {
} }
}, },
state: { state: {
height: 180,
disabled: false, //禁用编辑器 disabled: false, //禁用编辑器
fullscreen: false, //是否全屏 fullscreen: false, //是否全屏
preview: true, //是否显示预览 preview: true, //是否显示预览

File diff suppressed because one or more lines are too long

View File

@ -87,11 +87,14 @@ const tmpls = {
jumper: `<div class="input-box">前往 jumper: `<div class="input-box">前往
<input type="text" :duplex="inputPage" :keyup="setPage(null, $event)"> <input type="text" :duplex="inputPage" :keyup="setPage(null, $event)">
</div>`, </div>`,
slot: `<slot name="extra" />` slot: ''
} }
export default Anot.component('pager', { export default Anot.component('pager', {
__init__: function(props, state, next) { __init__: function(props, state, next) {
this.classList.add('do-pager')
this.classList.add('do-fn-noselect')
this.setAttribute(':class', "{{classList.join(' ')}}")
props.theme = +props.theme || 1 props.theme = +props.theme || 1
if (props.simpleMode) { if (props.simpleMode) {
props.theme = 1 props.theme = 1
@ -138,18 +141,13 @@ export default Anot.component('pager', {
layout = layout.map(it => { layout = layout.map(it => {
if (it === 'slot') { if (it === 'slot') {
if (slots && slots.extra) { if (slots && slots.extra) {
return slots.extra return slots.extra[0]
} }
} else { } else {
return tmpls[it] || '' return tmpls[it] || ''
} }
}) })
return ` return layout.join('\n')
<div
class="do-pager do-fn-noselect"
:class="{{classList.join(' ')}}">
${layout.join('\n')}
</div>`
}, },
componentWillMount: function() { componentWillMount: function() {
const { currPage, totalPage, props } = this const { currPage, totalPage, props } = this

View File

@ -8,7 +8,7 @@
@import "var.scss"; @import "var.scss";
.do-pager {height:auto;text-align:center;font-size:14px;color: nth($cgr, 1); .do-pager {display:block;height:auto;text-align:center;font-size:14px;color: nth($cgr, 1);
&.mini {line-height:30px; &.mini {line-height:30px;
.button,.page {min-width:30px;height:30px} .button,.page {min-width:30px;height:30px}

View File

@ -41,8 +41,7 @@ export default Anot.component('tree', {
return null return null
} }
return ` return `
<ul class="do-tree" :if="list.size()"> <section class="do-tree__item" :repeat="list" :class="{open: el.open, dir: el[props.children]}">
<li :repeat="list" :class="{open: el.open, dir: el[props.children]}">
<em <em
:class="{ :class="{
'do-icon-txt': !el.open && !el[props.children], 'do-icon-txt': !el.open && !el[props.children],
@ -59,8 +58,7 @@ export default Anot.component('tree', {
:click="__select(el)" :click="__select(el)"
:class="{active: el[props.id] === currItem}" :class="{active: el[props.id] === currItem}"
:text="el[props.label]"></span> :text="el[props.label]"></span>
<template <anot-tree
name="tree"
:attr="{ :attr="{
'multi-check': multiCheck, 'multi-check': multiCheck,
list: el[props.children], list: el[props.children],
@ -70,12 +68,13 @@ export default Anot.component('tree', {
label: props.label, label: props.label,
parent: props.parent, parent: props.parent,
children: props.children, children: props.children,
}"></template> }"></anot-tree>
</li> </section>
</ul>
` `
}, },
__init__: function(props, state, next) { __init__: function(props, state, next) {
this.classList.add('do-tree')
this.setAttribute(':if', 'list.size()')
props.id = props.id || 'id' props.id = props.id || 'id'
props.label = props.label || 'label' props.label = props.label || 'label'
props.parent = props.parent || 'parent' props.parent = props.parent || 'parent'

View File

@ -9,19 +9,22 @@
@import '../../css/var.scss'; @import '../../css/var.scss';
.do-tree {overflow:hidden;overflow-y:auto;position:relative;width:100%;height:100%;line-height:36px;font-size:15px;color:nth($cgr, 1); .do-tree {overflow:hidden;overflow-y:auto;position:relative;display:inline-block;width:100%;height:100%;line-height:36px;font-size:15px;color:nth($cgr, 1);
ul {width:100%;height:auto;} &__item {overflow:hidden; min-height:35px;margin:1px 0; white-space:nowrap; text-overflow:ellipsis;
li {overflow:hidden; min-height:35px;margin:1px 0; white-space:nowrap; text-overflow:ellipsis}
li ul {display:none;margin-left:20px;} .do-tree {display:none;margin-left:20px;}
li.open>ul {display:block;}
li em, em,span {display:inline-block;cursor:pointer;color:nth($cgr, 2);}
li span {display:inline-block;cursor:pointer;color:nth($cgr, 2);} em {float:left;padding:0 5px;font-size:20px;}
li em {float:left;padding:0 5px;font-size:20px;}
li span:hover {color:nth($cgr, 2);} span {
li span.active {color:nth($cgr, 3);font-weight:bold;}
li span.checkbox {float:left;position:relative;width:20px;height:20px;margin:8px 5px 8px 0;line-height:18px;border:1px solid nth($cgr, 1);border-radius:3px; font-size:20px;text-align:center; &:hover {color:nth($cgr, 2);}
&.active {color:nth($cgr, 3);font-weight:bold;}
&.checkbox {float:left;position:relative;width:20px;height:20px;margin:8px 5px 8px 0;line-height:18px;border:1px solid nth($cgr, 1);border-radius:3px; font-size:20px;text-align:center;}
} }
}
&__item.open>.do-tree {display:block;}
} }