mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[improvement] Field: optimize template (#560)
This commit is contained in:
parent
652bff5cb2
commit
5e3b53e880
@ -12,6 +12,16 @@ create({
|
|||||||
offset: Number
|
offset: Number
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
classes() {
|
||||||
|
const { span, offset } = this.data;
|
||||||
|
return this.classNames('custom-class', 'van-col', {
|
||||||
|
[`van-col--${span}`]: span,
|
||||||
|
[`van-col--${offset}`]: offset
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
setGutter(gutter) {
|
setGutter(gutter) {
|
||||||
const padding = `${gutter / 2}px`;
|
const padding = `${gutter / 2}px`;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<view
|
<view
|
||||||
class="custom-class van-col {{ span ? 'van-col--' + span : '' }} {{ offset ? 'van-col--offset-' + offset : '' }}"
|
class="{{ classes }}"
|
||||||
style="{{ style }}"
|
style="{{ style }}"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
@ -152,7 +152,6 @@ Page({
|
|||||||
| is-link | 是否展示右侧箭头并开启点击反馈 | `Boolean` | `false` |
|
| is-link | 是否展示右侧箭头并开启点击反馈 | `Boolean` | `false` |
|
||||||
| error | 是否将输入内容标红 | `Boolean` | `false` |
|
| error | 是否将输入内容标红 | `Boolean` | `false` |
|
||||||
| error-message | 底部错误提示文案,为空时不展示 | `String` | `''` |
|
| error-message | 底部错误提示文案,为空时不展示 | `String` | `''` |
|
||||||
| label-align | 文本对齐方式,可选值为 `center` `right` | `String` | `left` |
|
|
||||||
| input-align | 输入框内容对齐方式,可选值为 `center` `right` | `String` | `left` |
|
| input-align | 输入框内容对齐方式,可选值为 `center` `right` | `String` | `left` |
|
||||||
| autosize | 自适应内容高度,只对 textarea 有效 | `Boolean` | `false` |
|
| autosize | 自适应内容高度,只对 textarea 有效 | `Boolean` | `false` |
|
||||||
| icon | 输入框尾部图标 (可选值见 Icon 组件) | `String` | - |
|
| icon | 输入框尾部图标 (可选值见 Icon 组件) | `String` | - |
|
||||||
@ -185,7 +184,6 @@ Page({
|
|||||||
|
|
||||||
| 类名 | 说明 |
|
| 类名 | 说明 |
|
||||||
|-----------|-----------|
|
|-----------|-----------|
|
||||||
| custom-class | 根节点样式类 |
|
|
||||||
| input-class | 输入框样式类 |
|
| input-class | 输入框样式类 |
|
||||||
| icon-class | 右侧图标样式类 |
|
| icon-class | 右侧图标样式类 |
|
||||||
| placeholder-class | 占位内容样式类 |
|
| placeholder-class | 占位内容样式类 |
|
||||||
|
@ -19,7 +19,6 @@ create({
|
|||||||
required: Boolean,
|
required: Boolean,
|
||||||
iconClass: String,
|
iconClass: String,
|
||||||
clearable: Boolean,
|
clearable: Boolean,
|
||||||
labelAlign: String,
|
|
||||||
inputAlign: String,
|
inputAlign: String,
|
||||||
customClass: String,
|
customClass: String,
|
||||||
confirmType: String,
|
confirmType: String,
|
||||||
@ -60,6 +59,18 @@ create({
|
|||||||
showClear: false
|
showClear: false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
inputClass() {
|
||||||
|
const { data } = this;
|
||||||
|
return this.classNames('input-class', 'van-field__input', {
|
||||||
|
'van-field--error': data.error,
|
||||||
|
'van-field__textarea': data.type === 'textarea',
|
||||||
|
'van-field__input--disabled': data.disabled,
|
||||||
|
[`van-field--${data.inputAlign}`]: data.inputAlign
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onInput(event) {
|
onInput(event) {
|
||||||
const { value = '' } = event.detail || {};
|
const { value = '' } = event.detail || {};
|
||||||
|
@ -10,16 +10,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__control {
|
&__input {
|
||||||
border: 0;
|
border: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 24px;
|
||||||
resize: none;
|
resize: none;
|
||||||
display: block;
|
display: block;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
box-sizing: border-box;
|
min-height: 24px;
|
||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
|
box-sizing: border-box;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
|
||||||
&--disabled {
|
&--disabled {
|
||||||
@ -37,6 +39,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__clear-root {
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
&__clear,
|
&__clear,
|
||||||
&__icon-container,
|
&__icon-container,
|
||||||
&__button {
|
&__button {
|
||||||
@ -78,18 +84,4 @@
|
|||||||
&--error {
|
&--error {
|
||||||
color: $red;
|
color: $red;
|
||||||
}
|
}
|
||||||
|
|
||||||
&--label {
|
|
||||||
&-center {
|
|
||||||
.van-cell__title {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&-right {
|
|
||||||
.van-cell__title {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
required="{{ required }}"
|
required="{{ required }}"
|
||||||
custom-style="{{ customStyle }}"
|
custom-style="{{ customStyle }}"
|
||||||
title-width="{{ titleWidth }}"
|
title-width="{{ titleWidth }}"
|
||||||
custom-class="{{ customClass }} van-field {{ labelAlign ? 'van-field--label-' + labelAlign : '' }}"
|
custom-class="van-field"
|
||||||
>
|
>
|
||||||
<slot name="label" slot="title" />
|
<slot name="label" slot="title" />
|
||||||
<view class="van-field__body {{ type === 'textarea' ? 'van-field__body--textarea' : '' }}">
|
<view class="van-field__body {{ type === 'textarea' ? 'van-field__body--textarea' : '' }}">
|
||||||
<textarea
|
<textarea
|
||||||
wx:if="{{ type === 'textarea' }}"
|
wx:if="{{ type === 'textarea' }}"
|
||||||
class="input-class van-field__control van-field__textarea {{ inputAlign ? 'van-field--' + inputAlign : '' }} {{ error ? 'van-field--error' : '' }} {{ disabled ? 'van-field__control--disabled' : '' }}"
|
class="{{ inputClass }}"
|
||||||
focus="{{ focus }}"
|
focus="{{ focus }}"
|
||||||
value="{{ value }}"
|
value="{{ value }}"
|
||||||
disabled="{{ disabled }}"
|
disabled="{{ disabled }}"
|
||||||
@ -30,7 +30,7 @@
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
wx:else
|
wx:else
|
||||||
class="input-class van-field__control {{ inputAlign ? 'van-field--' + inputAlign : '' }} {{ error ? 'van-field--error' : '' }} {{ disabled ? 'van-field__control--disabled' : '' }}"
|
class="{{ inputClass }}"
|
||||||
type="{{ type }}"
|
type="{{ type }}"
|
||||||
focus="{{ focus }}"
|
focus="{{ focus }}"
|
||||||
value="{{ value }}"
|
value="{{ value }}"
|
||||||
@ -49,6 +49,7 @@
|
|||||||
<van-icon
|
<van-icon
|
||||||
wx:if="{{ showClear }}"
|
wx:if="{{ showClear }}"
|
||||||
name="clear"
|
name="clear"
|
||||||
|
class="van-field__clear-root"
|
||||||
custom-class="van-field__clear"
|
custom-class="van-field__clear"
|
||||||
bind:touchstart="onClear"
|
bind:touchstart="onClear"
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user