From b1fb8085089de59f4c39f6b79111033f0d1511a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Fri, 29 Jan 2021 11:05:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96input=E7=BB=84=E4=BB=B6;node-?= =?UTF-8?q?sass=E6=94=B9=E6=88=90sass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.dev.js | 2 +- build.prod.js | 2 +- src/css/reset-basic.css | 2 +- src/form/button.wc | 2 ++ src/form/input.wc | 46 +++++++++++++++++++++-------------------- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/build.dev.js b/build.dev.js index 4b15b10..8b6a3a1 100644 --- a/build.dev.js +++ b/build.dev.js @@ -4,7 +4,7 @@ require('es.shim') const log = console.log const fs = require('iofs') const path = require('path') -const scss = require('node-sass') +const scss = require('sass') const chokidar = require('chokidar') const chalk = require('chalk') diff --git a/build.prod.js b/build.prod.js index 38247ef..4164ddf 100644 --- a/build.prod.js +++ b/build.prod.js @@ -4,7 +4,7 @@ require('es.shim') const log = console.log const fs = require('iofs') const path = require('path') -const scss = require('node-sass') +const scss = require('sass') const chalk = require('chalk') const { minify } = require('terser') diff --git a/src/css/reset-basic.css b/src/css/reset-basic.css index b559871..0c0ec12 100644 --- a/src/css/reset-basic.css +++ b/src/css/reset-basic.css @@ -65,7 +65,7 @@ code, pre, samp {font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; --color-orange-2: rgb(241, 196, 15); --color-orange-3: rgb(205, 167, 13); /* default1 */ - --color-plain-a: rgba(242, 245, 252, 0.5); + --color-plain-a: rgba(150, 204, 248, 0.5); --color-plain-1: rgb(242, 245, 252); --color-plain-2: rgb(232, 235, 244); --color-plain-3: rgb(218, 225, 233); diff --git a/src/form/button.wc b/src/form/button.wc index 19a97cc..0cd01a7 100644 --- a/src/form/button.wc +++ b/src/form/button.wc @@ -417,6 +417,8 @@ export default class Button { }, 10) } break + + // case 'lazy': this.props.lazy = val >> 0 break diff --git a/src/form/input.wc b/src/form/input.wc index e4f6918..dab0cf0 100644 --- a/src/form/input.wc +++ b/src/form/input.wc @@ -342,7 +342,8 @@ export default class Input { autofocus: false, readonly: false, disabled: false, - passwd: false + passwd: false, + lazy: 0 // 输入建议并发拦截时间, 单位毫秒 } state = { @@ -455,25 +456,11 @@ export default class Input { this.state.mvidx = null } - _updateAttr() { - var { maxlength, minlength } = this.props - - if (maxlength && maxlength > 0) { - this.__INPUT__.setAttribute('maxlength', maxlength) - } else { - this.__INPUT__.removeAttribute('maxlength') - } - if (minlength && minlength > 0) { - this.__INPUT__.setAttribute('minlength', minlength) - } else { - this.__INPUT__.removeAttribute('minlength') - } - } - mounted() { var prepend = this.__PREPEND__.assignedNodes() var append = this.__APPEND__.assignedNodes() var { passwd } = this.props + this.stamp = 0 // 相同插槽, 只允许1个 while (prepend.length > 1) { @@ -490,8 +477,6 @@ export default class Input { this.__OUTER__.setAttribute('append', '') } - this._updateAttr() - // 键盘事件 this._handleSubmit = $.catch(this.__INPUT__, 'keydown', ev => { if (this.disabled || this.readOnly) { @@ -518,7 +503,15 @@ export default class Input { // 输入状态事件 this._handleChange = $.bind(this.__INPUT__, 'input', ev => { - ev.preventDefault() + let now = Date.now() + + // 并发拦截 + if (lazy && now - this.stamp < lazy) { + return + } + + this.stamp = now + this.dispatchEvent( new CustomEvent('fetch-suggest', { detail: { @@ -563,7 +556,6 @@ export default class Input { } unmount() { - $.unbind(this.__INPUT__, 'wheel', this._handleWheel) $.unbind(this.__INPUT__, 'keydown', this._handleSubmit) $.unbind(this.__INPUT__, 'input', this._handleChange) $.unbind(this.__LIST__, 'click', this._handleSelect) @@ -601,8 +593,18 @@ export default class Input { case 'maxlength': case 'minlength': - this.props[name] = val - this._updateAttr() + if (val === null) { + this.__INPUT__.removeAttribute(name) + } else { + let n = +val + if (n > 0) { + this.__INPUT__.setAttribute(name, +val) + } + } + break + + case 'lazy': + this.props.lazy = val >> 0 break case 'readonly':