123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <template>
- <view class="m-input-view">
- <input :inputmode="inputMode" :focus="focus_" :maxlength="maxlength" :type="inputType" :value="value" @input="onInput" class="m-input-input"
- placeholder-style="color:rgba(170, 170, 170, 1);" :placeholder="placeholder" :password="type==='password'&&!showPassword"
- @focus="onFocus" @blur="onBlur" />
- <!-- 优先显示密码可见按钮 -->
- <view v-if="clearable_&&!displayable_&&value.length" class="m-input-icon">
- <!-- <m-icon color="rgba(170, 170, 170, 1)" type="clear" size="20" @click="clear"></m-icon> -->
- <text class="cuIcon-roundclose" @click="clear"></text>
- </view>
- <view v-if="displayable_" class="m-input-icon">
- <!-- <m-icon :color="showPassword?'rgba(170, 170, 170, 1)':'#cccccc'" type="eye" size="20" @click="display"></m-icon> -->
- <!-- <image mode="scaleToFill" class="password-img" v-if="showPassword" src="../static/m-icon/sPassword.png" @click="display"></image> -->
- <!-- <image mode="scaleToFill" class="password-img" v-else src="../static/m-icon/cPassword.png" @click="display"></image> -->
- <text :class="showPassword?'cuIcon-attention':'cuIcon-attentionfill'" @click="display"></text>
- </view>
- </view>
- </template>
- <script>
- import mIcon from './m-icon/m-icon.vue'
- export default {
- components: {
- mIcon
- },
- props: {
- inputmode:{
- type: String,
- default: "none"
- },
- /**
- * 输入类型
- */
- type: String,
- /**
- * 值
- */
- value: String,
- /**
- * 占位符
- */
- placeholder: String,
- maxlength: {
- type: String,
- default: "-1"
- },
- /**
- * 是否显示清除按钮
- */
- clearable: {
- type: [Boolean, String],
- default: false
- },
- /**
- * 是否显示密码可见按钮
- */
- displayable: {
- type: [Boolean, String],
- default: false
- },
- /**
- * 自动获取焦点
- */
- focus: {
- type: [Boolean, String],
- default: false
- }
- },
- model: {
- prop: 'value',
- event: 'input'
- },
- data() {
- return {
- /**
- * 显示密码明文
- */
- showPassword: false,
- /**
- * 是否获取焦点
- */
- isFocus: false
- }
- },
- computed: {
- inputMode() {
- return this.inputmode
- },
- inputType() {
- const type = this.type
- return type === 'password' ? 'text' : type
- },
- clearable_() {
- return String(this.clearable) !== 'false'
- },
- displayable_() {
- return String(this.displayable) !== 'false'
- },
- focus_() {
- return String(this.focus) !== 'false'
- }
- },
- methods: {
- clear() {
- this.$emit('input', '')
- },
- display() {
- this.showPassword = !this.showPassword
- },
- onFocus() {
- this.isFocus = true
- },
- onBlur() {
- this.$nextTick(() => {
- this.isFocus = false
- })
- },
- onInput(e) {
- this.$emit('input', e.target.value)
- }
- }
- }
- </script>
- <style>
- .m-input-view {
- display: flex;
- flex-direction: row;
- align-items: center;
- width: 580rpx;
- flex: 1;
- padding: 0 10rpx;
- z-index: 100;
- /* position: relative; */
- }
- .m-input-input {
- flex: 1;
- width: 100%;
- height: 25px;
- color: rgba(170, 170, 170, 1);
- color: 18px;
- /* border: 1rpx solid #007AFF; */
- }
- .m-input-icon {
- width: 30px;
- /* height: 30px; */
- /* position: absolute;
- */
- margin-right: 40rpx;
- margin-left: 10rpx;
- }
- .m-input-icon text {
- font-size: 20px;
- color: rgba(170, 170, 170, 1)
- }
- .password-img {
- /* background-color: #007AFF; */
- width: 18px;
- height: 14px;
- }
- </style>
|