m-input.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view class="m-input-view">
  3. <input :inputmode="inputMode" :focus="focus_" :maxlength="maxlength" :type="inputType" :value="value" @input="onInput" class="m-input-input"
  4. placeholder-style="color:rgba(170, 170, 170, 1);" :placeholder="placeholder" :password="type==='password'&&!showPassword"
  5. @focus="onFocus" @blur="onBlur" />
  6. <!-- 优先显示密码可见按钮 -->
  7. <view v-if="clearable_&&!displayable_&&value.length" class="m-input-icon">
  8. <!-- <m-icon color="rgba(170, 170, 170, 1)" type="clear" size="20" @click="clear"></m-icon> -->
  9. <text class="cuIcon-roundclose" @click="clear"></text>
  10. </view>
  11. <view v-if="displayable_" class="m-input-icon">
  12. <!-- <m-icon :color="showPassword?'rgba(170, 170, 170, 1)':'#cccccc'" type="eye" size="20" @click="display"></m-icon> -->
  13. <!-- <image mode="scaleToFill" class="password-img" v-if="showPassword" src="../static/m-icon/sPassword.png" @click="display"></image> -->
  14. <!-- <image mode="scaleToFill" class="password-img" v-else src="../static/m-icon/cPassword.png" @click="display"></image> -->
  15. <text :class="showPassword?'cuIcon-attention':'cuIcon-attentionfill'" @click="display"></text>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import mIcon from './m-icon/m-icon.vue'
  21. export default {
  22. components: {
  23. mIcon
  24. },
  25. props: {
  26. inputmode:{
  27. type: String,
  28. default: "none"
  29. },
  30. /**
  31. * 输入类型
  32. */
  33. type: String,
  34. /**
  35. * 值
  36. */
  37. value: String,
  38. /**
  39. * 占位符
  40. */
  41. placeholder: String,
  42. maxlength: {
  43. type: String,
  44. default: "-1"
  45. },
  46. /**
  47. * 是否显示清除按钮
  48. */
  49. clearable: {
  50. type: [Boolean, String],
  51. default: false
  52. },
  53. /**
  54. * 是否显示密码可见按钮
  55. */
  56. displayable: {
  57. type: [Boolean, String],
  58. default: false
  59. },
  60. /**
  61. * 自动获取焦点
  62. */
  63. focus: {
  64. type: [Boolean, String],
  65. default: false
  66. }
  67. },
  68. model: {
  69. prop: 'value',
  70. event: 'input'
  71. },
  72. data() {
  73. return {
  74. /**
  75. * 显示密码明文
  76. */
  77. showPassword: false,
  78. /**
  79. * 是否获取焦点
  80. */
  81. isFocus: false
  82. }
  83. },
  84. computed: {
  85. inputMode() {
  86. return this.inputmode
  87. },
  88. inputType() {
  89. const type = this.type
  90. return type === 'password' ? 'text' : type
  91. },
  92. clearable_() {
  93. return String(this.clearable) !== 'false'
  94. },
  95. displayable_() {
  96. return String(this.displayable) !== 'false'
  97. },
  98. focus_() {
  99. return String(this.focus) !== 'false'
  100. }
  101. },
  102. methods: {
  103. clear() {
  104. this.$emit('input', '')
  105. },
  106. display() {
  107. this.showPassword = !this.showPassword
  108. },
  109. onFocus() {
  110. this.isFocus = true
  111. },
  112. onBlur() {
  113. this.$nextTick(() => {
  114. this.isFocus = false
  115. })
  116. },
  117. onInput(e) {
  118. this.$emit('input', e.target.value)
  119. }
  120. }
  121. }
  122. </script>
  123. <style>
  124. .m-input-view {
  125. display: flex;
  126. flex-direction: row;
  127. align-items: center;
  128. width: 580rpx;
  129. flex: 1;
  130. padding: 0 10rpx;
  131. z-index: 100;
  132. /* position: relative; */
  133. }
  134. .m-input-input {
  135. flex: 1;
  136. width: 100%;
  137. height: 25px;
  138. color: rgba(170, 170, 170, 1);
  139. color: 18px;
  140. /* border: 1rpx solid #007AFF; */
  141. }
  142. .m-input-icon {
  143. width: 30px;
  144. /* height: 30px; */
  145. /* position: absolute;
  146. */
  147. margin-right: 40rpx;
  148. margin-left: 10rpx;
  149. }
  150. .m-input-icon text {
  151. font-size: 20px;
  152. color: rgba(170, 170, 170, 1)
  153. }
  154. .password-img {
  155. /* background-color: #007AFF; */
  156. width: 18px;
  157. height: 14px;
  158. }
  159. </style>