first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View File

@@ -0,0 +1 @@
d172a121-0ded-47da-8a57-6654ce0afc3d

View File

@@ -0,0 +1,224 @@
import baseComponent from '../helpers/baseComponent'
import classNames from '../helpers/classNames'
import eventsMixin from '../helpers/eventsMixin'
import styleToCssString from '../helpers/styleToCssString'
const defaultEvents = {
onChange() {},
onFocus() {},
onBlur() {},
onConfirm() {},
onClear() {},
onError() {},
}
baseComponent({
behaviors: [eventsMixin({ defaultEvents })],
relations: {
'../field/index': {
type: 'ancestor',
},
},
properties: {
prefixCls: {
type: String,
value: 'wux-input',
},
label: {
type: String,
value: '',
},
extra: {
type: String,
value: '',
},
defaultValue: {
type: String,
value: '',
},
value: {
type: String,
value: '',
observer(newVal) {
if (this.data.controlled) {
this.updated(newVal)
}
},
},
controlled: {
type: Boolean,
value: false,
},
type: {
type: String,
value: 'text',
},
password: {
type: Boolean,
value: false,
},
placeholder: {
type: String,
value: '',
},
placeholderStyle: {
type: [String, Object],
value: '',
observer(newVal) {
this.setData({
extStyle: styleToCssString(newVal),
})
},
},
placeholderClass: {
type: String,
value: 'input-placeholder',
},
disabled: {
type: Boolean,
value: false,
},
maxlength: {
type: Number,
value: 140,
},
cursorSpacing: {
type: Number,
value: 11,
},
focus: {
type: Boolean,
value: false,
},
confirmType: {
type: String,
value: 'done',
},
confirmHold: {
type: Boolean,
value: false,
},
cursor: {
type: Number,
value: -1,
},
selectionStart: {
type: Number,
value: -1,
},
selectionEnd: {
type: Number,
value: -1,
},
adjustPosition: {
type: Boolean,
value: true,
},
clear: {
type: Boolean,
value: false,
},
error: {
type: Boolean,
value: false,
},
},
data: {
inputValue: '',
inputFocus: false,
extStyle: '',
},
computed: {
classes: ['prefixCls, disabled, inputFocus, error', function(prefixCls, disabled, inputFocus, hasError) {
const wrap = classNames(prefixCls, {
[`${prefixCls}--focus`]: inputFocus,
[`${prefixCls}--disabled`]: disabled,
[`${prefixCls}--error`]: hasError,
})
const label = `${prefixCls}__label`
const control = `${prefixCls}__control`
const item = `${prefixCls}__item`
const clear = `${prefixCls}__clear`
const error = `${prefixCls}__error`
const extra = `${prefixCls}__extra`
return {
wrap,
label,
control,
item,
clear,
error,
extra,
}
}],
},
methods: {
updated(inputValue) {
if (this.hasFieldDecorator) return
if (this.data.inputValue !== inputValue) {
this.setData({ inputValue })
}
},
onChange(e) {
const { value } = e.detail
if (!this.data.controlled) {
this.updated(value)
}
this.triggerEvent('change', e.detail)
},
onFocus(e) {
this.clearTimer()
this.setData({
inputFocus: true,
})
this.triggerEvent('focus', e.detail)
},
onBlur(e) {
this.setTimer()
this.triggerEvent('blur', e.detail)
},
onConfirm(e) {
this.triggerEvent('confirm', e.detail)
},
onClear(e) {
const params = { value: '' }
if (!this.data.controlled) {
this.updated(params.value)
}
this.triggerEvent('change', params)
this.triggerEvent('clear', params)
},
onError() {
const { inputValue: value } = this.data
this.triggerEvent('error', { value })
},
setTimer() {
this.clearTimer()
this.timeout = setTimeout(() => {
this.setData({
inputFocus: false,
})
}, 200)
},
clearTimer() {
if (this.timeout) {
clearTimeout(this.timeout)
this.timeout = null
}
},
},
attached() {
const { defaultValue, value, controlled } = this.data
const inputValue = controlled ? value : defaultValue
this.updated(inputValue)
},
})

View File

@@ -0,0 +1,3 @@
{
"component": true
}

View File

@@ -0,0 +1,41 @@
<view class="wux-class {{ classes.wrap }}">
<view class="{{ classes.label }}" wx:if="{{ label }}">{{ label }}</view>
<block wx:else>
<slot></slot>
</block>
<view class="{{ classes.control }}">
<input
class="{{ classes.item }}"
value="{{ inputValue }}"
type="{{ type }}"
password="{{ password }}"
placeholder="{{ placeholder }}"
placeholder-style="{{ extStyle }}"
placeholder-class="{{ placeholderClass }}"
disabled="{{ disabled }}"
maxlength="{{ maxlength }}"
cursor-spacing="{{ cursorSpacing }}"
focus="{{ focus }}"
confirm-type="{{ confirmType }}"
confirm-hold="{{ confirmHold }}"
cursor="{{ cursor }}"
selection-start="{{ selectionStart }}"
selection-end="{{ selectionEnd }}"
adjust-position="{{ adjustPosition }}"
bindinput="onChange"
bindfocus="onFocus"
bindblur="onBlur"
bindconfirm="onConfirm"
/>
</view>
<view class="{{ classes.clear }}" bindtap="onClear" wx:if="{{ clear && !disabled && inputValue && inputValue.length > 0 }}">
<icon type="clear" color="#B2B2B2" size="14" />
</view>
<view class="{{ classes.error }}" bindtap="onError" wx:if="{{ error }}">
<icon type="warn" color="#ef473a" size="14" />
</view>
<view class="{{ classes.extra }}" wx:if="{{ extra }}">{{ extra }}</view>
<block wx:else>
<slot name="footer"></slot>
</block>
</view>

View File

@@ -0,0 +1,50 @@
.wux-input {
position: relative;
display: -ms-flexbox;
display: flex;
-ms-flex-align: center;
align-items: center
}
.wux-input__label {
margin-left: 0;
margin-right: 10rpx;
text-align: left;
white-space: nowrap;
overflow: hidden;
width: 210rpx
}
.wux-input__control {
-ms-flex: 1;
flex: 1
}
.wux-input__item {
width: 100%;
border: 0;
outline: 0;
-webkit-appearance: none;
background-color: transparent;
font-size: inherit;
color: inherit;
height: 1.47058824em;
min-height: 1.47058824em;
line-height: 1.47058824
}
.wux-input__extra {
color: rgba(0,0,0,.45);
margin-left: 10rpx
}
.wux-input__error {
margin-left: 10rpx
}
.wux-input__clear {
display: none
}
.wux-input--focus .wux-input__clear {
display: block
}
.wux-input--disabled {
opacity: .3
}
.wux-input--error .wux-input__control {
color: #ef473a
}