From f2cb1beecfc1406cbdd8c78634b8f5defaa52a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Mon, 12 Aug 2019 21:26:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E6=B3=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.dev.js | 2 +- build.prod.js | 2 +- src/form/cascader.wc | 380 +++++++++++++++++++++++++++++++++++++++++++ src/form/select.wc | 345 +++++++++++++++++++++++++++++++++++++-- src/picker/date.wc | 22 +-- src/scroll/index.wc | 72 +++++--- 6 files changed, 774 insertions(+), 49 deletions(-) create mode 100644 src/form/cascader.wc diff --git a/build.dev.js b/build.dev.js index b90a39f..8588ec3 100644 --- a/build.dev.js +++ b/build.dev.js @@ -69,7 +69,7 @@ function mkWCFile({ style, html, js }) { let name = '' let props = '' - js = js.replace(/props = (\{[\w\W]*?\n\s{2}?\})/, function(s, m) { + js = js.replace(/props = (\{\}|\{[\w\W]*?\n\s{2}?\})/, function(s, m) { props = m var attr = new Function( `try { diff --git a/build.prod.js b/build.prod.js index 0265602..42f7050 100644 --- a/build.prod.js +++ b/build.prod.js @@ -81,7 +81,7 @@ function mkWCFile({ style, html, js }) { let name = '' let props = '' - js = js.replace(/props = (\{[\w\W]*?\n\s{2}?\})/, function(s, m) { + js = js.replace(/props = (\{\}|\{[\w\W]*?\n\s{2}?\})/, function(s, m) { props = m var attr = new Function( `var props = ${m}, attr = []; for(var i in props){attr.push(i)}; return attr` diff --git a/src/form/cascader.wc b/src/form/cascader.wc new file mode 100644 index 0000000..06c18f5 --- /dev/null +++ b/src/form/cascader.wc @@ -0,0 +1,380 @@ + + + + + diff --git a/src/form/select.wc b/src/form/select.wc index 8b65fb8..f23e3c7 100644 --- a/src/form/select.wc +++ b/src/form/select.wc @@ -1,31 +1,356 @@ - + diff --git a/src/picker/date.wc b/src/picker/date.wc index b871687..62b4b20 100644 --- a/src/picker/date.wc +++ b/src/picker/date.wc @@ -601,25 +601,15 @@ export default class DatePicker { break case 'max-date': - if (val) { - let tmp = new Date(val) - if (tmp.getFullYear()) { - this.props.max = { - year: tmp.getFullYear(), - month: tmp.getMonth(), - day: tmp.getDate() - } - this._renderCalendar() - } - } - this.removeAttribute('max-date') - break - case 'min-date': if (val) { + let v = +val + if (v === v) { + val = v + } let tmp = new Date(val) if (tmp.getFullYear()) { - this.props.min = { + this.props[name.slice(0, 3)] = { year: tmp.getFullYear(), month: tmp.getMonth(), day: tmp.getDate() @@ -627,7 +617,7 @@ export default class DatePicker { this._renderCalendar() } } - this.removeAttribute('min-date') + this.removeAttribute(name) break case 'value': diff --git a/src/scroll/index.wc b/src/scroll/index.wc index b57d45d..444f22a 100644 --- a/src/scroll/index.wc +++ b/src/scroll/index.wc @@ -81,9 +81,7 @@ const IS_FF = !!window.sidebar /* */ export default class Scroll { - props = { - v: '' - } + props = {} constructor() { /* render */ this.__BOX__ = this.root.children[1] @@ -91,6 +89,53 @@ export default class Scroll { this.__Y__ = this.root.children[3].children[0] } + get scrollTop() { + return this.__BOX__.scrollTop + } + + set scrollTop(n) { + // this.__BOX__.scrollTop + } + + get scrollLeft() { + return this.__BOX__.scrollLeft + } + + set scrollLeft(val) { + // this.__BOX__.scrollLeft + } + + get scrollHeight() { + return this.__BOX__.scrollHeight + } + + _fetchScrollX(moveX) { + var { sw, ow, xw, sh, oh, yh } = this.props + + if (moveX < 0) { + moveX = 0 + } else if (moveX > ow - xw) { + moveX = ow - xw + } + this.__BOX__.scrollLeft = (sw - ow) * (moveX / (ow - xw)) + this.__X__.style.transform = `translateX(${moveX}px)` + + return moveX + } + + _fetchScrollY(moveY) { + var { sw, ow, xw, sh, oh, yh } = this.props + + if (moveY < 0) { + moveY = 0 + } else if (moveY > oh - yh) { + moveY = oh - yh + } + this.__BOX__.scrollTop = (sh - oh) * (moveY / (oh - yh)) + this.__Y__.style.transform = `translateY(${moveY}px)` + return moveY + } + mounted() { // 初始化滚动条的位置和长度 this._initFn = ev => { @@ -187,28 +232,13 @@ export default class Scroll { moveX, moveY, mousemoveFn = ev => { - var { sw, ow, xw, sh, oh, yh, thumbY, thumbX } = this.props - + var { thumbY, thumbX } = this.props if (startX !== null) { - moveX = thumbX + ev.pageX - startX - if (moveX < 0) { - moveX = 0 - } else if (moveX > ow - xw) { - moveX = ow - xw - } - this.__BOX__.scrollLeft = (sw - ow) * (moveX / (ow - xw)) - this.__X__.style.transform = `translateX(${moveX}px)` + moveX = this._fetchScrollX(thumbX + ev.pageX - startX) } if (startY !== null) { - moveY = thumbY + ev.pageY - startY - if (moveY < 0) { - moveY = 0 - } else if (moveY > oh - yh) { - moveY = oh - yh - } - this.__BOX__.scrollTop = (sh - oh) * (moveY / (oh - yh)) - this.__Y__.style.transform = `translateY(${moveY}px)` + moveY = this._fetchScrollY(thumbY + ev.pageY - startY) } }, mouseupFn = ev => {