123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <template>
- <view class="app-view"
- :style="{'height': `${setHeight}rpx`, 'width': `${width}rpx`}"
- >
- <template v-if="type !== 'textarea'">
- <!-- #ifndef MP-TOUTIAO -->
- <input :disabled="disabled"
- :value="value || value === 0 ? value : defaultValue"
- :class="{'is-disabled': disabled, 'is-round': round, 'is-border': border}"
- class="app-input"
- :type="type"
- :password="password"
- :placeholder-style="placeholderStyle"
- :placeholder="placeholder"
- :focus="focus"
- :style="{
- 'padding-left': !center && icon ? '30rpx' : `${paddingLeft}rpx`,
- 'text-align': center ? 'center' : 'none',
- 'height': `${setHeight}rpx`,
- 'width': `${width}rpx`,
- 'color': `${color}`,
- backgroundColor: backgroundColor,
- borderRadius: `${radius}rpx`,
- borderColor: borderColor,
- }"
- @input="changeValue"
- @blur="blur"
- @confirm="confirm"
- />
- <!-- #endif -->
- <!-- MP-TOUTIAO focus属性有问题,去除。2020-02-24 -->
- <!-- #ifdef MP-TOUTIAO -->
- <input :disabled="disabled"
- :value="value || value === 0 ? value : defaultValue"
- :class="{'is-disabled': disabled, 'is-round': round, 'is-border': border}"
- class="app-input"
- :type="type"
- :password="password"
- :placeholder-style="placeholderStyle"
- :placeholder="placeholder"
- :style="{
- 'padding-left': !center && icon ? '30rpx' : `${paddingLeft}rpx`,
- 'text-align': center ? 'center' : 'none',
- 'height': `${setHeight}rpx`,
- 'width': `${width}rpx`,
- 'color': `${color}`,
- backgroundColor: backgroundColor,
- borderRadius: `${radius}rpx`,
- borderColor: borderColor,
- }"
- @input="changeValue"
- @blur="blur"
- @confirm="confirm"
- />
- <!-- #endif -->
- <icon v-if="icon" class="app-icon"
- :style="{'background-image': `url(${icon})`, 'left': center ? '42%': '1%'}"></icon>
- </template>
- <template v-else>
- <textarea :value="value ? value : defaultValue"
- :maxlength="maxLength ? maxLength : -1"
- @blur="blur"
- @confirm="confirm"
- :placeholder-style="placeholderStyle"
- :show-confirm-bar="showConfirmBar"
- :placeholder="placeholder"
- :auto-height="autoHeight"
- :disabled="disabled"
- @input="changeValue"
- class="app-input-textarea"
- :class="{'is-disabled': disabled, 'is-round': round, 'is-border': border}"
- :style="{
- 'color': `${color}`,
- backgroundColor: backgroundColor,
- borderRadius: `${radius}rpx`,
- padding: `24rpx ${paddingLeft}rpx`,
- borderColor: borderColor,
- }"
- >
- </textarea>
- </template>
- </view>
- </template>
- <script>
- export default {
- name: 'app-input',
- props: {
- type: String,
- password: Boolean,
- disabled: Boolean,
- placeholder: {
- default: '',
- type: String,
- },
- autoHeight: Boolean,
- showConfirmBar: Boolean,
- placeholderStyle: {
- default: 'color: #999999',
- },
- maxLength: String,
- value: {
- default: '',
- },
- round: Boolean,
- border: Number,
- borderColor: {
- default: '#c0c4cc',
- },
- icon: String,
- center: Boolean,
- size: String,
- width: String,
- color: {
- default: '#353535',
- type: String,
- },
- height: String,
- backgroundColor: String,
- radius: Number,
- focus: {
- type: Boolean,
- default: false,
- },
- paddingLeft: {
- default: 12,
- },
- defaultValue: {
- default: '',
- },
- },
- data() {
- return {
- newValue: this.value
- }
- },
- methods: {
- blur(event) {
- this.$emit('blur', event.detail);
- },
- confirm(event) {
- this.$emit('confirm', event.detail);
- },
- changeValue(value) {
- this.$emit('input', value.detail.value);
- }
- },
- computed: {
- setHeight: function () {
- if (this.height) return this.height;
- switch (this.size) {
- case 'large':
- return 100;
- case 'small':
- return 60;
- case 'medium':
- return 80;
- default:
- return 80;
- }
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .app-input {
- border-radius: #{10rpx};
- box-sizing: border-box;
- outline: none;
- height: #{80rpx};
- width: 100%;
- line-height: #{80rpx};
- color: $uni-general-color-three;
- }
- .is-border {
- border: #{2rpx} solid #dcdfe6;
- }
- .app-input:active {
- border-color: #c0c4cc
- }
- .app-input.is-disabled {
- background-color: #f5f7fa;
- border-color: #e4e7ed;
- color: #c0c4cc;
- cursor: not-allowed;
- }
- .is-round {
- border-radius: #{50rpx};
- }
- .app-view {
- position: relative;
- }
- .app-icon {
- width: #{25rpx};
- height: #{25rpx};
- position: absolute;
- top: 50%;
- transform: translateY(-50%);
- background-repeat: no-repeat;
- background-size: 100% 100%;
- }
- .app-input-textarea {
- max-height: 100%;
- width: 100%;
- word-wrap: break-word;
- }
- /* #ifdef MP-ALIPAY */
- .app-input,
- .app-input-textarea {
- overflow: hidden;
- }
- /* #endif */
- </style>
|