123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- <template>
- <view class="u-field" :class="{'u-border-top': borderTop, 'u-border-bottom': borderBottom }">
- <view class="u-field-inner" :class="[type == 'textarea' ? 'u-textarea-inner' : '', 'u-label-postion-' + labelPosition]">
- <view class="u-label" :class="[required ? 'u-required' : '']" :style="{
- justifyContent: justifyContent,
- flex: labelPosition == 'left' ? `0 0 ${labelWidth}rpx` : '1'
- }">
- <view class="u-icon-wrap" v-if="icon">
- <u-icon size="32" :custom-style="iconStyle" :name="icon" :color="iconColor" class="u-icon"></u-icon>
- </view>
- <slot name="icon"></slot>
- <text class="u-label-text" :class="[this.$slots.icon || icon ? 'u-label-left-gap' : '']">{{ label }}</text>
- </view>
- <view class="fild-body">
- <view class="u-flex-1 u-flex" :style="[inputWrapStyle]">
- <textarea v-if="type == 'textarea'" class="u-flex-1 u-textarea-class" :style="[fieldStyle]" :value="value"
- :placeholder="placeholder" :placeholderStyle="placeholderStyle" :disabled="disabled" :maxlength="inputMaxlength"
- :focus="focus" :autoHeight="autoHeight" :fixed="fixed" @input="onInput" @blur="onBlur" @focus="onFocus" @confirm="onConfirm"
- @tap="fieldClick" />
- <input
- v-else
- :style="[fieldStyle]"
- :type="type"
- class="u-flex-1 u-field__input-wrap"
- :value="value"
- :password="password || this.type === 'password'"
- :placeholder="placeholder"
- :placeholderStyle="placeholderStyle"
- :disabled="disabled"
- :maxlength="inputMaxlength"
- :focus="focus"
- :confirmType="confirmType"
- @focus="onFocus"
- @blur="onBlur"
- @input="onInput"
- @confirm="onConfirm"
- @tap="fieldClick"
- />
- </view>
- <u-icon :size="clearSize" v-if="clearable && value != '' && focused" name="close-circle-fill" color="#c0c4cc" class="u-clear-icon" @click="onClear"/>
- <view class="u-button-wrap"><slot name="right" /></view>
- <u-icon v-if="rightIcon" @click="rightIconClick" :name="rightIcon" color="#c0c4cc" :style="[rightIconStyle]" size="26" class="u-arror-right" />
- </view>
- </view>
- <view v-if="errorMessage !== false && errorMessage != ''" class="u-error-message" :style="{
- paddingLeft: labelWidth + 'rpx'
- }">{{ errorMessage }}</view>
- </view>
- </template>
- <script>
- export default {
- name:"u-field",
- props: {
- icon: String,
- rightIcon: String,
-
-
-
-
- required: Boolean,
- label: String,
- password: Boolean,
- clearable: {
- type: Boolean,
- default: true
- },
-
- labelWidth: {
- type: [Number, String],
- default: 130
- },
-
- labelAlign: {
- type: String,
- default: 'left'
- },
- inputAlign: {
- type: String,
- default: 'left'
- },
- iconColor: {
- type: String,
- default: '#606266'
- },
- autoHeight: {
- type: Boolean,
- default: true
- },
- errorMessage: {
- type: [String, Boolean],
- default: ''
- },
- placeholder: String,
- placeholderStyle: String,
- focus: Boolean,
- fixed: Boolean,
- value: [Number, String],
- type: {
- type: String,
- default: 'text'
- },
- disabled: {
- type: Boolean,
- default: false
- },
- maxlength: {
- type: [Number, String],
- default: 140
- },
- confirmType: {
- type: String,
- default: 'done'
- },
-
- labelPosition: {
- type: String,
- default: 'left'
- },
-
- fieldStyle: {
- type: Object,
- default() {
- return {}
- }
- },
-
- clearSize: {
- type: [Number, String],
- default: 30
- },
-
- iconStyle: {
- type: Object,
- default() {
- return {}
- }
- },
-
- borderTop: {
- type: Boolean,
- default: false
- },
-
- borderBottom: {
- type: Boolean,
- default: true
- },
-
- trim: {
- type: Boolean,
- default: true
- }
- },
- data() {
- return {
- focused: false,
- itemIndex: 0,
- };
- },
- computed: {
- inputWrapStyle() {
- let style = {};
- style.textAlign = this.inputAlign;
-
- if(this.labelPosition == 'left') {
- style.margin = `0 8rpx`;
- } else {
-
- style.marginRight = `8rpx`;
- }
- return style;
- },
- rightIconStyle() {
- let style = {};
- if (this.arrowDirection == 'top') style.transform = 'roate(-90deg)';
- if (this.arrowDirection == 'bottom') style.transform = 'roate(90deg)';
- else style.transform = 'roate(0deg)';
- return style;
- },
- labelStyle() {
- let style = {};
- if(this.labelAlign == 'left') style.justifyContent = 'flext-start';
- if(this.labelAlign == 'center') style.justifyContent = 'center';
- if(this.labelAlign == 'right') style.justifyContent = 'flext-end';
- return style;
- },
-
- justifyContent() {
- if(this.labelAlign == 'left') return 'flex-start';
- if(this.labelAlign == 'center') return 'center';
- if(this.labelAlign == 'right') return 'flex-end';
- },
-
- inputMaxlength() {
- return Number(this.maxlength)
- },
-
- fieldInnerStyle() {
- let style = {};
- if(this.labelPosition == 'left') {
- style.flexDirection = 'row';
- } else {
- style.flexDirection = 'column';
- }
-
- return style;
- }
- },
- methods: {
- onInput(event) {
- let value = event.detail.value;
-
- if(this.trim) value = this.$u.trim(value);
- this.$emit('input', value);
- },
- onFocus(event) {
- this.focused = true;
- this.$emit('focus', event);
- },
- onBlur(event) {
-
-
- setTimeout(() => {
- this.focused = false;
- }, 100)
- this.$emit('blur', event);
- },
- onConfirm(e) {
- this.$emit('confirm', e.detail.value);
- },
- onClear(event) {
- this.$emit('input', '');
- },
- rightIconClick() {
- this.$emit('right-icon-click');
- this.$emit('click');
- },
- fieldClick() {
- this.$emit('click');
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- @import "../../libs/css/style.components.scss";
-
- .u-field {
- font-size: 28rpx;
- padding: 20rpx 28rpx;
- text-align: left;
- position: relative;
- color: $u-main-color;
- }
- .u-field-inner {
- @include vue-flex;
- align-items: center;
- }
- .u-textarea-inner {
- align-items: flex-start;
- }
- .u-textarea-class {
- min-height: 96rpx;
- width: auto;
- font-size: 28rpx;
- }
- .fild-body {
- @include vue-flex;
- flex: 1;
- align-items: center;
- }
- .u-arror-right {
- margin-left: 8rpx;
- }
- .u-label-text {
- /* #ifndef APP-NVUE */
- display: inline-flex;
- /* #endif */
- }
- .u-label-left-gap {
- margin-left: 6rpx;
- }
- .u-label-postion-top {
- flex-direction: column;
- align-items: flex-start;
- }
- .u-label {
- width: 130rpx;
- flex: 1 1 130rpx;
- text-align: left;
- position: relative;
- @include vue-flex;
- align-items: center;
- }
- .u-required::before {
- content: '*';
- position: absolute;
- left: -16rpx;
- font-size: 14px;
- color: $u-type-error;
- height: 9px;
- line-height: 1;
- }
- .u-field__input-wrap {
- position: relative;
- overflow: hidden;
- font-size: 28rpx;
- height: 48rpx;
- flex: 1;
- width: auto;
- }
- .u-clear-icon {
- @include vue-flex;
- align-items: center;
- }
- .u-error-message {
- color: $u-type-error;
- font-size: 26rpx;
- text-align: left;
- }
- .placeholder-style {
- color: rgb(150, 151, 153);
- }
- .u-input-class {
- font-size: 28rpx;
- }
- .u-button-wrap {
- margin-left: 8rpx;
- }
- </style>
|