|
|
@@ -1,32 +1,10 @@
|
|
|
<template>
|
|
|
- <view :class="['nut-input', { 'nut-input-disabled': disabled }]">
|
|
|
+ <view :class="classes">
|
|
|
<view class="nut-input-label">
|
|
|
<view class="nut-input-require" v-if="requireShow">*</view>
|
|
|
<view v-if="label" class="label-string">{{ label }}</view>
|
|
|
</view>
|
|
|
-
|
|
|
- <view v-if="type === 'textarea'" class="nut-text">
|
|
|
- <textarea
|
|
|
- :style="styles"
|
|
|
- :rows="rows"
|
|
|
- @input="valueChange"
|
|
|
- v-model="state.curretvalue"
|
|
|
- class="nut-text-core"
|
|
|
- :maxlength="maxLength"
|
|
|
- :placeholder="placeholder"
|
|
|
- :disabled="disabled"
|
|
|
- :readonly="readonly"
|
|
|
- >
|
|
|
- </textarea>
|
|
|
- <span class="nut-text-limit" v-if="limitShow">
|
|
|
- <span :class="[{ 'nut-field-over': state.textNum > maxLength }]">{{
|
|
|
- state.textNum
|
|
|
- }}</span>
|
|
|
- <span>/{{ maxLength }}</span>
|
|
|
- </span>
|
|
|
- </view>
|
|
|
<input
|
|
|
- v-else
|
|
|
class="input-text"
|
|
|
:style="styles"
|
|
|
:type="type"
|
|
|
@@ -43,7 +21,7 @@
|
|
|
@click="handleClear"
|
|
|
class="nut-textinput-clear"
|
|
|
v-if="!disableClear && !readonly"
|
|
|
- v-show="type !== 'textarea' && active"
|
|
|
+ v-show="active && state.curretvalue.length > 0"
|
|
|
>
|
|
|
<nut-icon name="close-little" size="12px"></nut-icon>
|
|
|
</view>
|
|
|
@@ -54,43 +32,30 @@ import { ref, toRefs, reactive, computed } from 'vue';
|
|
|
import { createComponent } from '@/utils/create';
|
|
|
import { formatNumber } from './util';
|
|
|
|
|
|
-const { create } = createComponent('input');
|
|
|
-
|
|
|
+const { componentName, create } = createComponent('input');
|
|
|
+interface Events {
|
|
|
+ eventName: 'change' | 'focus' | 'blur' | 'clear' | 'update:value';
|
|
|
+ params: (string | number | Event)[];
|
|
|
+}
|
|
|
export default create({
|
|
|
props: {
|
|
|
type: {
|
|
|
type: String,
|
|
|
default: 'text'
|
|
|
},
|
|
|
- textAlign: {
|
|
|
- type: String,
|
|
|
- default: 'left'
|
|
|
- },
|
|
|
- limitShow: {
|
|
|
- type: Boolean,
|
|
|
- default: false
|
|
|
- },
|
|
|
- maxLength: {
|
|
|
- type: String,
|
|
|
+ value: {
|
|
|
+ type: [String, Number],
|
|
|
default: ''
|
|
|
},
|
|
|
- requireShow: {
|
|
|
- type: Boolean,
|
|
|
- default: false
|
|
|
- },
|
|
|
- rows: {
|
|
|
+ placeholder: {
|
|
|
type: String,
|
|
|
- default: ''
|
|
|
+ default: '请输入信息'
|
|
|
},
|
|
|
label: {
|
|
|
type: String,
|
|
|
default: ''
|
|
|
},
|
|
|
- placeholder: {
|
|
|
- type: String,
|
|
|
- default: '请输入信息'
|
|
|
- },
|
|
|
- readonly: {
|
|
|
+ requireShow: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
},
|
|
|
@@ -98,12 +63,16 @@ export default create({
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
},
|
|
|
- autosize: {
|
|
|
+ readonly: {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
},
|
|
|
- value: {
|
|
|
- type: [String, Number],
|
|
|
+ textAlign: {
|
|
|
+ type: String,
|
|
|
+ default: 'left'
|
|
|
+ },
|
|
|
+ maxLength: {
|
|
|
+ type: String,
|
|
|
default: ''
|
|
|
},
|
|
|
disableClear: {
|
|
|
@@ -115,25 +84,13 @@ export default create({
|
|
|
emits: ['change', 'update:value', 'blur', 'focus', 'clear', 'error'],
|
|
|
|
|
|
setup(props, { emit }) {
|
|
|
- interface Events {
|
|
|
- eventName:
|
|
|
- | 'change'
|
|
|
- | 'focus'
|
|
|
- | 'blur'
|
|
|
- | 'clear'
|
|
|
- | 'update:value'
|
|
|
- | 'error';
|
|
|
- params: (string | number | Event)[];
|
|
|
- }
|
|
|
-
|
|
|
const {
|
|
|
label,
|
|
|
placeholder,
|
|
|
disabled,
|
|
|
readonly,
|
|
|
requireShow,
|
|
|
- maxLength,
|
|
|
- rows
|
|
|
+ maxLength
|
|
|
} = props;
|
|
|
const { value } = toRefs(props);
|
|
|
const active = ref(false);
|
|
|
@@ -141,14 +98,15 @@ export default create({
|
|
|
curretvalue: value,
|
|
|
textNum: String(value.value).length
|
|
|
});
|
|
|
+ const classes = computed(() => {
|
|
|
+ return {
|
|
|
+ [componentName]: true,
|
|
|
+ 'nut-input-disabled': disabled
|
|
|
+ };
|
|
|
+ });
|
|
|
const styles = computed(() => {
|
|
|
- const rize =
|
|
|
- props.type == 'textarea'
|
|
|
- ? `'resize':${props.autosize ? 'none' : 'horizontal'}`
|
|
|
- : '';
|
|
|
return {
|
|
|
- 'text-align': props.textAlign,
|
|
|
- rize
|
|
|
+ 'text-align': props.textAlign
|
|
|
};
|
|
|
});
|
|
|
const emitChange = (envs: Array<Events>) => {
|
|
|
@@ -162,12 +120,6 @@ export default create({
|
|
|
|
|
|
if (maxLength && val.length > Number(maxLength)) {
|
|
|
val = val.slice(0, Number(maxLength));
|
|
|
- emitChange([
|
|
|
- {
|
|
|
- eventName: 'error',
|
|
|
- params: [val]
|
|
|
- }
|
|
|
- ]);
|
|
|
}
|
|
|
if (props.type == 'digit') {
|
|
|
val = formatNumber(val, true);
|
|
|
@@ -176,8 +128,6 @@ export default create({
|
|
|
val = formatNumber(val, false);
|
|
|
}
|
|
|
state.textNum = val.length;
|
|
|
- // input.value = val;
|
|
|
- //state.curretvalue = val;
|
|
|
emitChange([
|
|
|
{
|
|
|
eventName: 'update:value',
|
|
|
@@ -243,7 +193,6 @@ export default create({
|
|
|
placeholder,
|
|
|
label,
|
|
|
disabled,
|
|
|
- rows,
|
|
|
state,
|
|
|
styles,
|
|
|
active,
|
|
|
@@ -252,6 +201,7 @@ export default create({
|
|
|
valueFocus,
|
|
|
valueBlur,
|
|
|
handleClear,
|
|
|
+ classes,
|
|
|
emitChange
|
|
|
};
|
|
|
}
|