input.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <up-input :readonly="readonly" :shape="shape" :placeholder="placeholder" :placeholderClass="placeholderClass"
  3. :suffixIcon="suffixIcon" :border="border" :adjustPosition="adjustPosition" :suffixIconStyle="suffixIconStyle"
  4. :model-value="inputValue" :disabled="disabled" :maxlength="maxlength" :type="type" :clearable="clearable"
  5. :placeholderStyle="placeholderStyle" :password="password" :confirm-type="confirmType" :focus="focus"
  6. :inputAlign="inputAlign" :fontSize="fontSize" :color="color" :prefixIcon="prefixIcon"
  7. :prefixIconStyle="prefixIconStyle" @clear="clear" @change="change" @update:modelValue="input" @confirm="confirm"
  8. @keyboardheightchange="keyboardheightchange" @focus="focusChange" @blur="blur"
  9. :style="{ '--bordercolor': borderColor, '--bgColor': bgColor }">
  10. <template #prefix>
  11. <slot name="prefix"></slot>
  12. </template>
  13. <template #suffix>
  14. <slot name="suffix">
  15. <view class="search_right" @click.stop="search" v-if="suffixIcon">
  16. <u-icon :name="suffixIcon" color="var(--gray1)" size="20"></u-icon>
  17. </view>
  18. </slot>
  19. </template>
  20. </up-input>
  21. </template>
  22. <script setup>
  23. import { ref, nextTick, watch } from "vue";
  24. const props = defineProps({
  25. placeholder: {
  26. type: String,
  27. default: ''
  28. },
  29. modelValue: {
  30. type: [String, Number],
  31. default: ''
  32. },
  33. type: {
  34. type: String,
  35. default: 'text'
  36. },
  37. clearable: Boolean,
  38. password: Boolean,
  39. readonly: Boolean,
  40. shape: {
  41. type: String,
  42. default: 'circle' // circle | square
  43. },
  44. suffixIcon: {
  45. type: String,
  46. default: ''
  47. },
  48. border: {
  49. type: String,
  50. default: 'surround' // surround | bottom | none
  51. },
  52. suffixIconStyle: {
  53. type: [String, Object],
  54. default: ''
  55. },
  56. placeholderStyle: {
  57. type: [String, Object],
  58. default: 'color: #adb8cc'
  59. },
  60. placeholderClass: {
  61. type: String,
  62. default: ''
  63. },
  64. adjustPosition: Boolean,
  65. disabled: Boolean,
  66. maxlength: {
  67. type: Number,
  68. default: -1
  69. },
  70. confirmType: {
  71. type: String,
  72. default: 'done'
  73. },
  74. focus: Boolean,
  75. inputAlign: {
  76. type: String,
  77. default: 'left'
  78. },
  79. fontSize: {
  80. type: String,
  81. default: '14px'
  82. },
  83. color: {
  84. type: String,
  85. default: 'var(--inputText)'
  86. },
  87. prefixIcon: {
  88. type: String,
  89. default: ''
  90. },
  91. prefixIconStyle: {
  92. type: [String, Object],
  93. default: ''
  94. },
  95. borderColor: {
  96. type: String,
  97. default: 'var(--inputBorder)'
  98. },
  99. bgColor: {
  100. type: String,
  101. default: 'var(--light)'
  102. }
  103. })
  104. const emit = defineEmits(['update:modelValue', 'search', 'clear', 'change', 'confirm', 'keyboardheightchange', 'focusChange', 'blur'])
  105. const inputValue = ref(props.modelValue)
  106. const search = () => {
  107. emit('search');
  108. }
  109. const clear = () => {
  110. emit('clear')
  111. }
  112. const change = (value) => {
  113. emit('change', value)
  114. }
  115. const input = (value) => {
  116. inputValue.value = value;
  117. emit('update:modelValue', value)
  118. }
  119. const confirm = (value) => {
  120. emit('confirm', value)
  121. }
  122. const keyboardheightchange = () => {
  123. emit('keyboardheightchange')
  124. }
  125. const focusChange = () => {
  126. emit('focusChange')
  127. }
  128. const blur = (value) => {
  129. emit('blur', value)
  130. }
  131. watch(() => props.modelValue, (newValue) => {
  132. inputValue.value = newValue;
  133. });
  134. </script>
  135. <style lang="less" scoped>
  136. .u-border {
  137. border-color: var(--borderColor) !important;
  138. box-shadow: 0 0 0 1px var(--borderColor) inset;
  139. }
  140. .u-input {
  141. padding: 0 8px !important;
  142. background-color: var(--inputBg);
  143. /deep/ .u-input__content__prefix-icon {
  144. margin-right: 8px;
  145. }
  146. /deep/ .uni-input-placeholder{
  147. color: var(--text-01) !important;
  148. }
  149. /deep/ .u-input__content__field-wrapper__field {
  150. height: 32px;
  151. }
  152. }
  153. </style>