Commit b5184d556fba67ade9e8632d03b8d930f730ccb0
1 parent
163a5cd1
Exists in
master
新增输入区组件
Showing
3 changed files
with
148 additions
and
4 deletions
Show diff stats
components/button/index.vue
| ... | ... | @@ -23,13 +23,22 @@ export default { |
| 23 | 23 | round: Boolean, |
| 24 | 24 | square: Boolean, |
| 25 | 25 | disabled: Boolean, |
| 26 | + plain: Boolean, | |
| 26 | 27 | }, |
| 27 | 28 | computed: { |
| 28 | 29 | style: function() { |
| 29 | 30 | return `display: ${this.block ? '' : 'inline-block'};` ; |
| 30 | 31 | }, |
| 31 | 32 | classRender: function() { |
| 32 | - return [this.size, this.disabled ? 'disabled' : '', this.block ? 'block' : '', this.type, this.round ? 'round' : '', this.square ? 'square' : '']; | |
| 33 | + return [ | |
| 34 | + this.size, | |
| 35 | + this.type, | |
| 36 | + this.disabled ? 'disabled' : '', | |
| 37 | + this.block ? 'block' : '', | |
| 38 | + this.round ? 'round' : '', | |
| 39 | + this.square ? 'square' : '', | |
| 40 | + this.plain ? 'plain' : '', | |
| 41 | + ]; | |
| 33 | 42 | } |
| 34 | 43 | }, |
| 35 | 44 | methods: { | ... | ... |
| ... | ... | @@ -0,0 +1,135 @@ |
| 1 | +<template> | |
| 2 | + <view class="zui-input-field"> | |
| 3 | + <view class="zui-input-field__label"> | |
| 4 | + <view class="zui-input-field__label-title"> | |
| 5 | + <text class="zui-input-field__label-text">{{ label }}</text> | |
| 6 | + <zui-icon v-if="required" class="zui-input-field__label-asterisk" name="asterisk"></zui-icon> | |
| 7 | + </view> | |
| 8 | + <text v-if="showError" class="zui-input-field__label-error">{{ errorMessage }}</text> | |
| 9 | + </view> | |
| 10 | + <view class="zui-input-field__input"> | |
| 11 | + <zui-input class="zui-input-field__input-input" v-model="model" @input="onInput" :placeholder="placeholder" clearable></zui-input> | |
| 12 | + <view v-if="$slots['input-right']" class="zui-input-field__input-right"> | |
| 13 | + <slot name="input-right"></slot> | |
| 14 | + </view> | |
| 15 | + </view> | |
| 16 | + </view> | |
| 17 | +</template> | |
| 18 | + | |
| 19 | +<script> | |
| 20 | +import ZuiIcon from '../icon'; | |
| 21 | +import ZuiInput from '../input'; | |
| 22 | + | |
| 23 | +export default { | |
| 24 | + components: { | |
| 25 | + ZuiIcon, | |
| 26 | + ZuiInput | |
| 27 | + }, | |
| 28 | + props: { | |
| 29 | + value: [String, Number], | |
| 30 | + regExp: String, | |
| 31 | + label: String, | |
| 32 | + required: Boolean, | |
| 33 | + placeholder: String, | |
| 34 | + errorMessage: String, | |
| 35 | + }, | |
| 36 | + data: function() { | |
| 37 | + return { | |
| 38 | + model: this.value, | |
| 39 | + }; | |
| 40 | + }, | |
| 41 | + watch: { | |
| 42 | + value: function(val) { | |
| 43 | + console.log(val) | |
| 44 | + this.model = val; | |
| 45 | + } | |
| 46 | + }, | |
| 47 | + computed: { | |
| 48 | + showError: function() { | |
| 49 | + if (this.regExp) { | |
| 50 | + const regExp = new RegExp(this.regExp.replace(/^(\s|\/)+|(\s|\/)+$/g, '')); | |
| 51 | + return !regExp.test(this.model); | |
| 52 | + } else { | |
| 53 | + return !!this.errorMessage; | |
| 54 | + } | |
| 55 | + } | |
| 56 | + }, | |
| 57 | + methods: { | |
| 58 | + onInput: function(value) { | |
| 59 | + this.model = value; | |
| 60 | + this.$emit('input', value); | |
| 61 | + } | |
| 62 | + } | |
| 63 | +} | |
| 64 | +</script> | |
| 65 | + | |
| 66 | +<style lang="scss"> | |
| 67 | +.zui-input-field { | |
| 68 | + width: 100%; | |
| 69 | + position: relative; | |
| 70 | + background-color: $color-white; | |
| 71 | + &__label { | |
| 72 | + display: flex; | |
| 73 | + align-items: center; | |
| 74 | + justify-content: space-between; | |
| 75 | + font-size: $font-md * 0.9; | |
| 76 | + color: $color-text-minor; | |
| 77 | + padding: $h-gap-sm $v-gap-md 0; | |
| 78 | + &-title { | |
| 79 | + display: flex; | |
| 80 | + align-items: center; | |
| 81 | + text-wrap: none; | |
| 82 | + white-space: nowrap; | |
| 83 | + word-break: break-all; | |
| 84 | + box-sizing: border-box; | |
| 85 | + } | |
| 86 | + &-text { | |
| 87 | + color: $color-black; | |
| 88 | + } | |
| 89 | + &-asterisk { | |
| 90 | + color: #FF0000; | |
| 91 | + font-size: $font-sm * 0.9; | |
| 92 | + padding-left: 10upx; | |
| 93 | + padding-bottom: 3upx; | |
| 94 | + } | |
| 95 | + &-error { | |
| 96 | + flex: auto; | |
| 97 | + display: flex; | |
| 98 | + justify-content: flex-end; | |
| 99 | + color: #FF5257; | |
| 100 | + padding-left: $v-gap-sm; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + &::after { | |
| 104 | + position: absolute; | |
| 105 | + content: ''; | |
| 106 | + width: 100%; | |
| 107 | + left: 0; | |
| 108 | + bottom: 0; | |
| 109 | + height: 1px; | |
| 110 | + background-color: $color-border; | |
| 111 | + transform: scale(1, 0.5); | |
| 112 | + transform-origin: center bottom; | |
| 113 | + } | |
| 114 | + &__input { | |
| 115 | + display: flex; | |
| 116 | + justify-content: space-between; | |
| 117 | + align-items: center; | |
| 118 | + padding: $h-gap-sm $v-gap-md; | |
| 119 | + box-sizing: border-box; | |
| 120 | + &-input { | |
| 121 | + flex: auto; | |
| 122 | + } | |
| 123 | + &-placeholder { | |
| 124 | + color: $color-border; | |
| 125 | + } | |
| 126 | + &-right { | |
| 127 | + padding-left: $v-gap-sm; | |
| 128 | + text-wrap: none; | |
| 129 | + white-space: nowrap; | |
| 130 | + word-break: break-all; | |
| 131 | + box-sizing: border-box; | |
| 132 | + } | |
| 133 | + } | |
| 134 | +} | |
| 135 | +</style> | ... | ... |
components/input/index.vue
| ... | ... | @@ -15,7 +15,7 @@ export default { |
| 15 | 15 | ZuiIcon, |
| 16 | 16 | }, |
| 17 | 17 | props: { |
| 18 | - value: String, | |
| 18 | + value: [String, Number], | |
| 19 | 19 | type: { |
| 20 | 20 | type: String, |
| 21 | 21 | default: 'text' |
| ... | ... | @@ -43,8 +43,8 @@ export default { |
| 43 | 43 | this.$emit('input', value); |
| 44 | 44 | }, |
| 45 | 45 | onClear: function() { |
| 46 | - this.model = undefined; | |
| 47 | - this.$emit('input', undefined); | |
| 46 | + this.model = ''; | |
| 47 | + this.$emit('input', ''); | |
| 48 | 48 | this.$emit('clear'); |
| 49 | 49 | } |
| 50 | 50 | } | ... | ... |