|
@@ -13,20 +13,20 @@
|
|
<slot name="prepend"></slot>
|
|
<slot name="prepend"></slot>
|
|
</div>
|
|
</div>
|
|
<input
|
|
<input
|
|
|
|
+ class="el-input__inner"
|
|
|
|
+ v-model="currentValue"
|
|
:type="type"
|
|
:type="type"
|
|
:name="name"
|
|
:name="name"
|
|
- class="el-input__inner"
|
|
|
|
:placeholder="placeholder"
|
|
:placeholder="placeholder"
|
|
- v-model="currentValue"
|
|
|
|
:disabled="disabled"
|
|
:disabled="disabled"
|
|
:readonly="readonly"
|
|
:readonly="readonly"
|
|
- @focus="$emit('onfocus', currentValue)"
|
|
|
|
- @blur="handleBlur"
|
|
|
|
:number="number"
|
|
:number="number"
|
|
:maxlength="maxlength"
|
|
:maxlength="maxlength"
|
|
:minlength="minlength"
|
|
:minlength="minlength"
|
|
:autocomplete="autoComplete"
|
|
:autocomplete="autoComplete"
|
|
ref="input"
|
|
ref="input"
|
|
|
|
+ @focus="$emit('onfocus', currentValue)"
|
|
|
|
+ @blur="handleBlur"
|
|
>
|
|
>
|
|
<!-- input 图标 -->
|
|
<!-- input 图标 -->
|
|
<i class="el-input__icon" :class="[icon ? 'el-icon-' + icon : '']" v-if="icon"></i>
|
|
<i class="el-input__icon" :class="[icon ? 'el-icon-' + icon : '']" v-if="icon"></i>
|
|
@@ -36,12 +36,27 @@
|
|
<slot name="append"></slot>
|
|
<slot name="append"></slot>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
- <!-- 写成垂直的方式会导致 placeholder 失效, 蜜汁bug -->
|
|
|
|
- <textarea v-else v-model="currentValue" class="el-textarea__inner" :name="name" :placeholder="placeholder" :disabled="disabled" :readonly="readonly" @focus="$emit('onfocus', currentValue)" @blur="handleBlur"></textarea>
|
|
|
|
|
|
+ <textarea
|
|
|
|
+ v-else
|
|
|
|
+ class="el-textarea__inner"
|
|
|
|
+ v-model="currentValue"
|
|
|
|
+ ref="textarea"
|
|
|
|
+ :name="name"
|
|
|
|
+ :placeholder="placeholder"
|
|
|
|
+ :disabled="disabled"
|
|
|
|
+ :style="textareaStyle"
|
|
|
|
+ :readonly="readonly"
|
|
|
|
+ :rows="rows"
|
|
|
|
+ :maxlength="maxlength"
|
|
|
|
+ :minlength="minlength"
|
|
|
|
+ @focus="$emit('onfocus', currentValue)"
|
|
|
|
+ @blur="handleBlur">
|
|
|
|
+ </textarea>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
<script>
|
|
<script>
|
|
import emitter from 'main/mixins/emitter';
|
|
import emitter from 'main/mixins/emitter';
|
|
|
|
+ import calcTextareaHeight from './calcTextareaHeight';
|
|
|
|
|
|
export default {
|
|
export default {
|
|
name: 'ElInput',
|
|
name: 'ElInput',
|
|
@@ -82,6 +97,14 @@
|
|
type: Boolean,
|
|
type: Boolean,
|
|
default: false
|
|
default: false
|
|
},
|
|
},
|
|
|
|
+ autosize: {
|
|
|
|
+ type: [Boolean, Object],
|
|
|
|
+ default: false
|
|
|
|
+ },
|
|
|
|
+ rows: {
|
|
|
|
+ type: Number,
|
|
|
|
+ default: 2
|
|
|
|
+ },
|
|
autoComplete: {
|
|
autoComplete: {
|
|
type: String,
|
|
type: String,
|
|
default: 'off'
|
|
default: 'off'
|
|
@@ -98,12 +121,22 @@
|
|
|
|
|
|
inputSelect() {
|
|
inputSelect() {
|
|
this.$refs.input.select();
|
|
this.$refs.input.select();
|
|
|
|
+ },
|
|
|
|
+ resizeTextarea() {
|
|
|
|
+ var { autosize, type } = this;
|
|
|
|
+ if (!autosize || type !== 'textarea') {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ const minRows = autosize ? autosize.minRows : null;
|
|
|
|
+ const maxRows = autosize ? autosize.maxRows : null;
|
|
|
|
+ this.textareaStyle = calcTextareaHeight(this.$refs.textarea, minRows, maxRows);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- currentValue: ''
|
|
|
|
|
|
+ currentValue: this.value,
|
|
|
|
+ textareaStyle: {}
|
|
};
|
|
};
|
|
},
|
|
},
|
|
|
|
|
|
@@ -111,6 +144,10 @@
|
|
this.$on('inputSelect', this.inputSelect);
|
|
this.$on('inputSelect', this.inputSelect);
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ mounted() {
|
|
|
|
+ this.resizeTextarea();
|
|
|
|
+ },
|
|
|
|
+
|
|
computed: {
|
|
computed: {
|
|
validating() {
|
|
validating() {
|
|
return this.$parent.validating;
|
|
return this.$parent.validating;
|
|
@@ -118,16 +155,13 @@
|
|
},
|
|
},
|
|
|
|
|
|
watch: {
|
|
watch: {
|
|
- 'value': {
|
|
|
|
- immediate: true,
|
|
|
|
- handler(val) {
|
|
|
|
- this.currentValue = val;
|
|
|
|
- }
|
|
|
|
|
|
+ 'value'(val, oldValue) {
|
|
|
|
+ this.currentValue = val;
|
|
|
|
+ this.resizeTextarea();
|
|
},
|
|
},
|
|
|
|
|
|
'currentValue'(val) {
|
|
'currentValue'(val) {
|
|
this.$emit('input', val);
|
|
this.$emit('input', val);
|
|
- this.$emit('onchange', val);
|
|
|
|
this.dispatch('form-item', 'el.form.change', [val]);
|
|
this.dispatch('form-item', 'el.form.change', [val]);
|
|
}
|
|
}
|
|
}
|
|
}
|