Merge branch 'master' of github.com:9th-js/wcui

master
yutent 2023-05-05 19:02:30 +08:00
commit de2f5a9d00
5 changed files with 41 additions and 85 deletions

View File

@ -16,7 +16,10 @@ import '../icon/index.js'
const ANIMATION = { const ANIMATION = {
duration: 100, duration: 100,
custom: [{ transform: 'scaleY(0)' }, { transform: 'scaleY(1)' }] custom: [
{ transform: 'scaleY(0)', opacity: 0 },
{ transform: 'scaleY(1)', opacity: 1 }
]
} }
class Input extends Component { class Input extends Component {
@ -38,8 +41,6 @@ class Input extends Component {
lazy: 0 // 并发拦截时间, 单位毫秒 lazy: 0 // 并发拦截时间, 单位毫秒
} }
#list = [] #list = []
#originList = []
#isComposing = false
#selectIndex = -1 #selectIndex = -1
#listShowing = false #listShowing = false
#stamp = 0 #stamp = 0
@ -132,16 +133,11 @@ class Input extends Component {
left: 0; left: 0;
top: calc(100% + 4px); top: calc(100% + 4px);
width: 100%; width: 100%;
height: auto;
max-height: 200px;
padding: 4px 0; padding: 4px 0;
border-radius: 4px; border-radius: 4px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
transform-origin: top; transform-origin: top;
.scroller {
max-height: 200px;
}
.list { .list {
width: 100%; width: 100%;
} }
@ -375,8 +371,6 @@ class Input extends Component {
ref="input" ref="input"
@input=${this.handleInput} @input=${this.handleInput}
@change=${this.handleChange} @change=${this.handleChange}
@compositionstart=${this.handleCompositionstart}
@compositionend=${this.handleCompositionend}
@keydown=${this.handleKeyDown} @keydown=${this.handleKeyDown}
@focus=${this.handleFocus} @focus=${this.handleFocus}
placeholder=${this.placeholder} placeholder=${this.placeholder}
@ -409,73 +403,39 @@ class Input extends Component {
</div> </div>
` `
} }
handleCompositionstart() {
this.#isComposing = true
}
handleCompositionend() {
this.#isComposing = false
this.filterSuggestList()
}
filterSuggestList() {
if (!this.#originList.length) {
return
}
if (!this.value.trim()) {
this.#list = []
} else {
this.#list = this.#originList.filter(li =>
li.value.startsWith(this.value)
)
}
if (!this.#listShowing) {
this.#listShowing = true
this.$refs.suggestion.$animate()
}
this.$requestUpdate()
}
handleInput(e) { handleInput(e) {
let { lazy } = this let { lazy } = this
this.value = e.currentTarget.value this.value = e.currentTarget.value
if (lazy && Date.now() - this.#stamp < lazy) { if (lazy && Date.now() - this.#stamp < lazy) {
return return
} }
this.#stamp = Date.now() this.#stamp = Date.now()
if (!this.#isComposing) {
this.filterSuggestList()
}
this.emitFetchSuggest() this.emitFetchSuggest()
} }
handleClickItem(e) { handleClickItem(e) {
let index = e.target.getAttribute('index') let index = e.target.getAttribute('index')
this.value = this.#list[index].value this.#selectIndex = index
this.#list = [this.#list[index]] this.emitSelect()
this.$refs.suggestion.$animate(true)
this.#listShowing = false
this.$emit('select')
} }
clear() { clear() {
this.$refs.input.value = '' this.$refs.input.value = ''
this.value = '' this.value = ''
if (this.#originList.length) { this.$emit('change')
this.filterSuggestList() this.$emit('input')
}
} }
handleChange() { handleChange() {
this.$emit('change') this.$emit('change')
} }
handleKeyDown(e) { handleKeyDown(e) {
let { lazy, minlength, value } = this let { lazy, minlength, value } = this
if (e.keyCode === 13) { if (e.keyCode === 13) {
e.preventDefault() e.preventDefault()
if (this.#selectIndex > -1 && this.#listShowing) { if (this.#selectIndex > -1 && this.#listShowing) {
this.value = this.#list[this.#selectIndex].value return this.emitSelect()
this.#list = [this.#list[this.#selectIndex]]
this.#selectIndex = 0
this.$requestUpdate()
this.$refs.suggestion.$animate(true)
this.#listShowing = false
return this.$emit('select') //输入建议存在,则第1次回车的时候, 不触发提交
} }
if (lazy && Date.now() - this.#stamp < lazy) { if (lazy && Date.now() - this.#stamp < lazy) {
return return
@ -486,6 +446,7 @@ class Input extends Component {
} }
return this.$emit('submit') return this.$emit('submit')
} }
if (e.keyCode === 38 || e.keyCode === 40) { if (e.keyCode === 38 || e.keyCode === 40) {
e.preventDefault() e.preventDefault()
let step = e.keyCode === 38 ? -1 : 1 let step = e.keyCode === 38 ? -1 : 1
@ -497,17 +458,33 @@ class Input extends Component {
if (this.#selectIndex > this.#list.length - 1) { if (this.#selectIndex > this.#list.length - 1) {
this.#selectIndex = this.#list.length - 1 this.#selectIndex = this.#list.length - 1
} }
let target = this.$refs.list.children[this.#selectIndex]
this.$refs.scroller.scrollTop = target.offsetTop - 150
this.$requestUpdate() this.$requestUpdate()
} }
} }
// 触发列表选择
emitSelect() {
let item = this.#list[this.#selectIndex]
this.value = item.value
this.$refs.suggestion.$animate(true)
this.#listShowing = false
this.$requestUpdate()
this.$emit('change')
this.$emit('input')
this.$emit('select', {
index: this.#selectIndex,
value: item
})
}
emitFetchSuggest() { emitFetchSuggest() {
this.$emit('fetch-suggest', { this.$emit('fetch-suggest', {
value: this.value, value: this.value,
send: list => { send: list => {
this.#originList = this.#list = list.slice(0, 5) this.#list = list.slice(0, 10)
this.filterSuggestList() this.#selectIndex = -1
this.$requestUpdate()
} }
}) })
} }

View File

@ -261,6 +261,7 @@ class ImagePreview extends Component {
` `
} }
} }
ImagePreview.reg('image-preview') ImagePreview.reg('image-preview')
let instance = null let instance = null

View File

@ -6,7 +6,6 @@
import { css, html, Component, styleMap } from '@bd/core' import { css, html, Component, styleMap } from '@bd/core'
import '../icon/index.js' import '../icon/index.js'
import './preview.js'
class Image extends Component { class Image extends Component {
static props = { static props = {
@ -17,11 +16,6 @@ class Image extends Component {
alt: { alt: {
type: String, type: String,
default: null default: null
},
previewSrcList: {
type: Array,
default: [],
attribute: false
} }
} }
@ -60,11 +54,7 @@ class Image extends Component {
this.status = 'loaded' this.status = 'loaded'
this.$requestUpdate() this.$requestUpdate()
} }
onClick() {
if (this.previewSrcList.length) {
window.imagePreview(this.previewSrcList)
}
}
render() { render() {
let { let {
lazy, lazy,
@ -72,13 +62,13 @@ class Image extends Component {
status, status,
fit, fit,
alt, alt,
previewSrcList,
'referrer-policy': referrerPolicy 'referrer-policy': referrerPolicy
} = this } = this
let styles = styleMap({ let styles = styleMap({
'object-fit': fit, 'object-fit': fit
cursor: previewSrcList.length ? 'pointer' : 'default'
}) })
let $slot = '' let $slot = ''
if (status === 'loading') { if (status === 'loading') {
@ -90,7 +80,7 @@ class Image extends Component {
} }
return html` return html`
<div class="wc-image" ref="wrapper" @click=${this.onClick}> <div class="wc-image" ref="wrapper">
<img <img
style=${styles} style=${styles}
src=${src} src=${src}

View File

@ -9,7 +9,7 @@ import './drawer/index.js'
import './form/index.js' import './form/index.js'
import './icon/index.js' import './icon/index.js'
import './image/index.js' import './image/index.js'
import './image/preview.js' import './image-preview/index.js'
import './layer/index.js' import './layer/index.js'
import './notify/index.js' import './notify/index.js'
import './pager/index.js' import './pager/index.js'

View File

@ -4,9 +4,8 @@
* @date 2023/04/28 16:14:10 * @date 2023/04/28 16:14:10
*/ */
import { css, html, Component, nextTick, styleMap } from '@bd/core' import { css, html, Component, styleMap } from '@bd/core'
import '../form/button.js' import '../form/button.js'
import '../icon/index.js'
class Popconfirm extends Component { class Popconfirm extends Component {
static props = { static props = {
@ -51,17 +50,6 @@ class Popconfirm extends Component {
attribute: false attribute: false
}, },
//组件状态
left: {
type: Number,
default: 0,
attribute: false
},
top: {
type: Number,
default: 0,
attribute: false
},
show: { show: {
type: Boolean, type: Boolean,
default: false, default: false,